<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.en.stne.net/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.en.stne.net/index.php?feed=atom&amp;target=Glest+Durnham&amp;title=Special%3AContributions</id>
		<title>STNE Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.en.stne.net/index.php?feed=atom&amp;target=Glest+Durnham&amp;title=Special%3AContributions"/>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Special:Contributions/Glest+Durnham"/>
		<updated>2026-04-19T14:26:42Z</updated>
		<subtitle>From STNE Wiki</subtitle>
		<generator>MediaWiki 1.16.0</generator>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Basic_course</id>
		<title>Scripting:Basic course</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Basic_course"/>
				<updated>2011-03-22T18:06:16Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: scripts are case insensitive these days&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedTranslation}}&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
'''This is a beginners course for the STNE engine script. It is not complete and probably not 100% correct. I have basically taught myself to use the STNE engine through trail and error, bad translation, good examples, and the benevolence of others. My spelling sucks. I'm sorry. If you see a mistake please fix it.'''&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
==Vorwort==&lt;br /&gt;
Much like the German version this course is aimed primarily at those who have never programmed and would like to start scripting in STNE. Please realize it is not easy and it will take a little while before you realize results. Be patient and keep at it! Like all good things it takes effort but it should be worth the time you put into it. I wish you the best of luck.&lt;br /&gt;
&lt;br /&gt;
==Chapter 1 - Strings==&lt;br /&gt;
In programming a String is a series of characters. The chapter title would be a String as would this text. The famous line &amp;quot;Hello World!&amp;quot; is also a String and it is this String you will be working with.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Hello World!&amp;quot; ===&lt;br /&gt;
We don't really know where it started but when first embarking on learning a programming language the first program you tend to write will be &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
In the STNE engine this is very easy.&lt;br /&gt;
First launch the script editor under:&lt;br /&gt;
Database -&amp;gt; Script Editor -&amp;gt; Create a new script -&amp;gt; Custom script without input wizard&lt;br /&gt;
Then you will click &amp;quot;Edit source code&amp;quot;.&lt;br /&gt;
In the text field provided type: &lt;br /&gt;
&amp;lt;pre&amp;gt;WriteLine('Hello World!');&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now click Save&amp;amp;Run.&lt;br /&gt;
Did it work? If not double check your input. Are the capital letters capital? Are there opening and closing quote marks and parentheses? Does it end with a semicolon?&lt;br /&gt;
When it works you should see the line:&lt;br /&gt;
&amp;lt;pre&amp;gt;Hello World!&amp;lt;/pre&amp;gt;&lt;br /&gt;
Congratulations you are now programming. Try making a program that says:&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;Hello World!&lt;br /&gt;
Live long and prosper!&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your code should look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;WriteLine('Hello World!');&lt;br /&gt;
WriteLine('Live long and prosper!');&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note every line of code ends with a semicolon.&lt;br /&gt;
But what if you want to write everything on one line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;Hello World! Live long and prosper!&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is done by use of the &amp;amp; symbol:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;WriteLine('Hello World!'&amp;amp;' Live long and prosper!');&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
The &amp;amp; symbol allows you to combine two Strings. It literately sticks them right next to each other which is why ' Live long and prosper!' has the preceding space. See what happens when you remove it!&lt;br /&gt;
&amp;quot;But wait!&amp;quot; You say. &amp;quot;I could simple code: &amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;WriteLine('Hello World! Live long and prosper!');&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt; and never have to deal with the &amp;amp; symbol!&amp;quot;&lt;br /&gt;
True, and as a programmer you will have many choices of different ways to do things. But the '&amp;amp;' is important as you will find out in the next chapter.&lt;br /&gt;
&lt;br /&gt;
===Summary: Strings===&lt;br /&gt;
&lt;br /&gt;
* A String is a sequence of several characters.&lt;br /&gt;
* A String is output, or printed, using the command ''WriteLine();''.&lt;br /&gt;
* You may use the character &amp;amp; to combine one String with another within the parameters, or parentheses, of ''WriteLine();''.&lt;br /&gt;
&lt;br /&gt;
==Chapter 2 - Variables==&lt;br /&gt;
===Basic types===&lt;br /&gt;
Think of a variable as a reference that you can use again and again and again. They can be a word, a number, or true/false. These are all called [[Scripting:DataTypes|Data Types]] and, of course, each has a special name:&lt;br /&gt;
* String  - a series of characters&lt;br /&gt;
* Integer - a whole number&lt;br /&gt;
* Boolean - decision (True/False)&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
Imagine you have a gigantic project with hundreds of lines of code. Dozens upon dozens of times your code will output the lines:&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;Captains log Stardate:&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
You could code:&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;WriteLine('Captains log Stardate:');&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
every single time and maybe misspell it. Or you could use a variable.&lt;br /&gt;
Before a variable can be used, or called, it must be created. You do this with the word &amp;quot;Var&amp;quot; followed by the name followed by &amp;quot;As&amp;quot; followed by the type of variable it is followed by &amp;quot;=&amp;quot; followed by the data to be stored.&lt;br /&gt;
&lt;br /&gt;
Sound complicated?&lt;br /&gt;
Bear with us.&lt;br /&gt;
&lt;br /&gt;
In keeping with the above example let us declare a String variable that contains the line: 'Captains log Stardate:'&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;Var CL As String = 'Captains Log Stardate:';&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
the name can be anything you choose it to be. In this example we used the letters CL because they are an acronym for Captains Log but you could as easily use LC or X or foo. Choose something that makes sense to you because you will use it through your code.&lt;br /&gt;
No two variables can have the same name though.&lt;br /&gt;
&lt;br /&gt;
Lets create a number, or integer, variable:&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;Var SD As Integer = 234121;&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Notice that because this is a number the type is Integer and because this is not a String we DO NOT put quotes around the assignment (what follows the equal sign).&lt;br /&gt;
When you run this program, though, it doesn't seem to do much. That is because everything is happening behind the curtain and trust us you don't want to look back there! But if we add an output statement:&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;WriteLine(CL &amp;amp; SD);&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Things start to happen. Cool huh? Just in case your having trouble your code should look like this:&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;Var CL As String = 'Captains Log Stardate:';&lt;br /&gt;
Var SD As Integer = 234121;&lt;br /&gt;
WriteLine(CL &amp;amp; SD);&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remember that variable assignments always have to come before variable calls. Your code is executed one line at a time and it needs to know what CL is before it can WriteLine CL. Also note the clever use of the &amp;amp; symbol. It stuck the integer and the string together!&lt;br /&gt;
The output looks like:&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;Captains Log Stardate:234121&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
See if you can find a way to get a space between the colon and the number...&lt;br /&gt;
&amp;lt;Pre&amp;gt;&amp;lt;nowiki&amp;gt;Captains Log Stardate: 234121&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Converting One Data Type to Another===&lt;br /&gt;
In many programming languages including an older version of the STNE engine you often need to convert variables from one type to another.&lt;br /&gt;
For instance if you had a variable:&lt;br /&gt;
&amp;lt;Pre&amp;gt;Var number As Integer = 12345;&amp;lt;/Pre&amp;gt;&lt;br /&gt;
You couldn't use it in certain functions like &lt;br /&gt;
&amp;lt;Pre&amp;gt;WriteLine(number);&amp;lt;/pre&amp;gt;&lt;br /&gt;
Because the parameters for WriteLine() would only accept Strings and the variable 'number' is an Integer.&lt;br /&gt;
&lt;br /&gt;
In that case you would use another function CStr() to convert it to a String:&lt;br /&gt;
&amp;lt;Pre&amp;gt;CStr(number)&amp;lt;/Pre&amp;gt;&lt;br /&gt;
You could even place that inside the parameters of WriteLine():&lt;br /&gt;
&amp;lt;Pre&amp;gt;WriteLine(CStr(number));&amp;lt;/Pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Likewise you could covert a String to it's integer value with CInt();&lt;br /&gt;
&lt;br /&gt;
But lucky for us the language is much smarter now and this has become a problem of such little significance that we can not even think up a satisfactory example.&lt;br /&gt;
&lt;br /&gt;
===Rules for Naming Variables===&lt;br /&gt;
There are some rules for naming your variables&lt;br /&gt;
* Do not duplicate names. Each script you make must only use a name once, and those names are case insensitive. This means that FOO and foo are actually the same.&lt;br /&gt;
* Do not use spaces. Use capital letters to signify different words. &lt;br /&gt;
* Do not use reserved names. Certain names are needed by the complier and by the STNE system and should be avoided. This names include dates, commands for system-defined functions, and features.&lt;br /&gt;
* For clear coding consider starting your variable name with a three digits representing the variable type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;intDeutNeeded&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Remember always attempt to make your code as easy to understand as possible. Someday you will come back to it and try to understand what you were attempting.&lt;br /&gt;
&lt;br /&gt;
===Summary: Variables===&lt;br /&gt;
&lt;br /&gt;
* A variable takes the place of &amp;quot;hard coded&amp;quot; data.&lt;br /&gt;
* To create a variable use 'VAR &amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt; AS &amp;lt;b&amp;gt;Datentype&amp;lt;/b&amp;gt;;''&lt;br /&gt;
* To assign data to a variable you use ''&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt; = &amp;lt;b&amp;gt;Inhalt&amp;lt;/b&amp;gt;;''&lt;br /&gt;
* To output a variable use ''WriteLine(&amp;lt;b&amp;gt;Name&amp;lt;/b&amp;gt;);'' This can be very important when debugging.&lt;br /&gt;
* The ''&amp;amp;'' symbol connects variables withing a  function call''WriteLine();''&lt;br /&gt;
&lt;br /&gt;
==Chapter 3 - Control Structures==&lt;br /&gt;
Now that you know how to create and use variables it is time to tackle Control Structures. These are the decision making lines that will make your scripts very powerful.&lt;br /&gt;
&lt;br /&gt;
===If - Else===&lt;br /&gt;
This works exactly how it sounds. &amp;lt;B&amp;gt;IF&amp;lt;/B&amp;gt; evaluates a statement and when it is true will execute the next few lines of code that are within curly braces &amp;quot;{&amp;quot; and &amp;quot;}&amp;quot;. You can also include an &amp;lt;B&amp;gt;ELSE&amp;lt;/B&amp;gt; statement that will execute when the &amp;lt;B&amp;gt;IF&amp;lt;/B&amp;gt; evaluates to false.&lt;br /&gt;
For example this code evaluates a variable and executes the code within the curly braces in response:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Var tribbles As Boolean = True;&lt;br /&gt;
If (tribbles){&lt;br /&gt;
  WriteLine('Oh no! The food!');&lt;br /&gt;
}&lt;br /&gt;
Else{&lt;br /&gt;
  WriteLine('The food is safe.');&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
When the code runs it will evaluate tribbles. See it is true and then run the code within the curly braces and ignore the code after the ELSE statement. Try it out.&lt;br /&gt;
 &lt;br /&gt;
You can also use an IF statement to compare amounts. In that case you would use the equal symbol:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Var EPSamount As Integer = 44;&lt;br /&gt;
If (EPSamount = 45){&lt;br /&gt;
  WriteLine('We have exactly ' &amp;amp; EPSamount &amp;amp; ' available');&lt;br /&gt;
}&lt;br /&gt;
Else{&lt;br /&gt;
  WriteLine('Im givin her all shes got, Cpatain!');&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Since EPSamount does not equal 45 this the statement will evaluate to false. It then ignores the code after the IF statement and executes the code after the ELSE statement.&lt;br /&gt;
&lt;br /&gt;
You can also use &amp;quot;&amp;lt;&amp;quot;,&amp;quot;&amp;gt;&amp;quot;,&amp;quot;&amp;lt;=&amp;quot;,&amp;quot;&amp;gt;=&amp;quot; for different types of comparisons. In that order and in English those are called &amp;quot;less then&amp;quot;, &amp;quot;greater then&amp;quot;, &amp;quot;less then or equal to&amp;quot;, and &amp;quot;greater then or equal to&amp;quot;. These can be a little confusing at first so remember the bigger side of the symbol is toward the larger number. &amp;quot;a&amp;lt;b&amp;quot; says that a is less then b. b is greater.&lt;br /&gt;
You can also you the words &amp;quot;AND&amp;quot; and &amp;quot;OR&amp;quot; to write more complex IF statements with multiple tests but each test will need to be inside it's own parentheses which can get very confusing very fast:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
If ((dilth&amp;gt;5)AND(deut&amp;gt;10)AND(ANTIM&amp;gt;10)){&lt;br /&gt;
  WriteLine('Ready for deep space exploration');&lt;br /&gt;
}&lt;br /&gt;
Else{&lt;br /&gt;
  WriteLine('Are you crazy? We wont make it past pluto!');&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remember the more clear your code is the easier it is for someone in the future, probably you, to understand it so you might re-write the above statement using more variables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Var dilth AS Boolean = (dilthAmount&amp;gt;5);&lt;br /&gt;
Var deut AS Boolean = (deutAmount&amp;gt;10);&lt;br /&gt;
Var antiM As Boolean = (antiMAmount&amp;gt;10);&lt;br /&gt;
If ((dilth)AND(deut)AND(antiM)){&lt;br /&gt;
  WriteLine('Ready for deep space exploration');&lt;br /&gt;
}&lt;br /&gt;
Else{&lt;br /&gt;
  WriteLine('Are you crazy? We wont make it past pluto!');&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
It is completely up to you!&lt;br /&gt;
&lt;br /&gt;
===Loops===&lt;br /&gt;
The next important control structure to learn are loops. A loop works like an if statement, that is executing the lines of code within curly braces &amp;quot;{&amp;quot; &amp;quot;}&amp;quot; but a loop will not exit until the conditions that started become false.&lt;br /&gt;
&lt;br /&gt;
====While====&lt;br /&gt;
Consider the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Var ore As integer= 0;&lt;br /&gt;
WriteLine('Do you need ore?');&lt;br /&gt;
while ((ore &amp;lt; 12)){&lt;br /&gt;
  WriteLine('We have ' &amp;amp; ore &amp;amp;' ore. We need more ore!');&lt;br /&gt;
  ore = ore + 2;&lt;br /&gt;
}&lt;br /&gt;
WriteLine('Thanks. We can start making Duranium.');&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
When executing the WHILE repeats until ore reaches twelve and then it moves on. This type of code can cause problems though when you write a statement that will never evaluate false:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Var isKilingon As Boolean = True;&lt;br /&gt;
while (isKilingon){&lt;br /&gt;
  WriteLine('Today is a good day to die!');&lt;br /&gt;
}&lt;br /&gt;
WriteLine('Enough battle!');&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
If run this code would print the line 'Today is a good day to die!' forever and never print the line 'Enough battle'. Luckily when this happens the STNE engine steps in and kills the script.&lt;br /&gt;
&lt;br /&gt;
====Do====&lt;br /&gt;
DO loops work just like WHILE loops except that regardless the evaluation a DO will execute at least once. &lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
VAR friendlyShip AS Boolean = False;&lt;br /&gt;
WriteLine('Ship on Federation sensors');&lt;br /&gt;
Do(friendlyShip){&lt;br /&gt;
  WriteLine('Hale them.');&lt;br /&gt;
}&lt;br /&gt;
WriteLine('No response. Open fire!');&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
When this script is run, regardless of the fact that the statement evaluated false it will run once. If something happened inside the statement that made it become true though it would run again.&lt;br /&gt;
&lt;br /&gt;
====For====&lt;br /&gt;
A FOR loop works just like a WHILE loop except it has a built in integer variable which it increments after every loop. This makes it very good for incrementing. Consider our earlier example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Var ore As integer= 0;&lt;br /&gt;
WriteLine('Do you need ore?');&lt;br /&gt;
while ((ore &amp;lt; 12)){&lt;br /&gt;
  WriteLine('We have ' &amp;amp; ore &amp;amp;' ore. We need more ore!');&lt;br /&gt;
  ore = ore + 2;&lt;br /&gt;
}&lt;br /&gt;
WriteLine('Thanks. We can start making Duranium.');&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
This could also be written using a FOR loop:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Var ore As integer;&lt;br /&gt;
WriteLine('Do you need ore?');&lt;br /&gt;
for(ore=0 To 12 Step 2){&lt;br /&gt;
  WriteLine('We have ' &amp;amp; ore &amp;amp;' ore. We need more ore!');&lt;br /&gt;
}&lt;br /&gt;
WriteLine('Thanks. We can start making Duranium.');&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
See how the incrementation is taken care of in the parameters, or between the parentheses? It takes the integer variable ore from 0 to 12 by sets of 2.&lt;br /&gt;
&lt;br /&gt;
If you do not specify a step it will assume the step is 1.&lt;br /&gt;
&lt;br /&gt;
==Chapter 4 - Functions==&lt;br /&gt;
===Introduction===&lt;br /&gt;
The last object to learn about are functions. A function is a series of lines of code that can be called from main to run again and again. Consider that we have the following code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
WriteLine('Get them out of there!');&lt;br /&gt;
WriteLine('Attempting to beam up away-team');&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
But you want to run that ten times.&lt;br /&gt;
You could write those two lines ten times or you could make a function. In that way a function can act similar to variables though as you will see they are much more powerful.&lt;br /&gt;
To create a function you use the following formula 'Function' followed by the name you give it, followed by the symbols &amp;quot;(){}&amp;quot;&lt;br /&gt;
Here is an example using the code above:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Function BeamUp(){&lt;br /&gt;
  WriteLine('Get them out of there!');&lt;br /&gt;
  WriteLine('Attempting to beam up away-team');&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now every time BeamUp() is called it looks through the entire script for the Function BeamUp() and will run those two lines of code. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
WriteLine('We are at the Borg ship.');&lt;br /&gt;
BeamUp();&lt;br /&gt;
WriteLine('We are at the Klingon colony.');&lt;br /&gt;
BeamUp();&lt;br /&gt;
Function BeamUp(){&lt;br /&gt;
  WriteLine('Get them out of there!');&lt;br /&gt;
  WriteLine('Attempting to beam up away-team!');&lt;br /&gt;
}&lt;br /&gt;
WriteLine('We are at the Syndicate station');&lt;br /&gt;
BeamUp();&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Parameters===&lt;br /&gt;
But it gets better. You can pass a function variables making it more versatile. To specify what types of variables a function can be passed you need to declare them between the parenthesis &amp;quot;()&amp;quot;. These are called the Functions Parameters. You declare a function in the parameters the same way you do in regular code and you can declare as many variables of any type as you want so long as you separate them by comas. For example&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Function BeamUp(number As Int32, crew As Boolean, teamName As String){&lt;br /&gt;
  If(crew){&lt;br /&gt;
    WriteLine('Beaming up ' &amp;amp; number &amp;amp; ' ' &amp;amp; teamName &amp;amp; '.');&lt;br /&gt;
    WriteLine('Attempting to beam up away-team!');&lt;br /&gt;
    Else{&lt;br /&gt;
      WriteLine('There is nobody there');&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
For some reason when the compiler checks for errors it replaces the word Integer with Int32. Don't worry. It you write either one your code will still work.&lt;br /&gt;
Now when you make the function call you need to pass it values that match it's parameters.&lt;br /&gt;
In the above example you might call it this way:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
BeamUp(5, True, Medics);&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Function BeamUp(number As Int32, crew As Boolean, teamName As String){&lt;br /&gt;
  If(crew){&lt;br /&gt;
    WriteLine('Beaming up ' &amp;amp; number &amp;amp; ' ' &amp;amp; teamName &amp;amp; '.');&lt;br /&gt;
    WriteLine('Attempting to beam up away-team!');&lt;br /&gt;
    Else{&lt;br /&gt;
      WriteLine('There is nobody there');&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
WriteLine('We are at the Borg ship.');&lt;br /&gt;
BeamUp();&lt;br /&gt;
WriteLine('We are at the Klingon colony.');&lt;br /&gt;
BeamUp();&lt;br /&gt;
WriteLine('We are at the Syndicate station');&lt;br /&gt;
BeamUp();&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also for clarity consider keeping your Functions separate from your main code either all above or all bellow.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nachdem wir nun über ein paar Grundlagen verfügen, wollen wir uns den wirklich interessanten Dingen zuwenden, der Steuerung von Spielinhalten durch Scripte.&lt;br /&gt;
&lt;br /&gt;
Um mit Schiffen zu interagieren gibt es eine Sammlung von Methoden, welche im Shipmanager zu finden sind.&lt;br /&gt;
Hierzu müssen wir dem Shipmanager als erstes Mitteilen, welches bzw. welche Flotte er verwenden soll.&lt;br /&gt;
&lt;br /&gt;
Hierführ gibt es die Befehle:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;ShipManager.BenutzeSchiff(NCC-Nummer des Schiffes);&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
bzw.&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;ShipManager.BenutzeFlotte(ID der Flotte);&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Damit weiß der ShipManager schonmal welches Schiff, bzw. welche Flotte die Aktionen ausführen soll.&lt;br /&gt;
&lt;br /&gt;
Mit dem Shipmanager können folgende Aktionen ausgeführt werden:&lt;br /&gt;
*An- und Abdocken&lt;br /&gt;
*Alarm Stufe ändern&lt;br /&gt;
*Aus Flotten austreten&lt;br /&gt;
*Aus Orbit einfliegen austreten &lt;br /&gt;
*Benennen(Name As String)&lt;br /&gt;
*Deuterium sammeln (Nur mit FP)&lt;br /&gt;
*Erz sammeln (Nur mit FP)&lt;br /&gt;
*Fliegen&lt;br /&gt;
*Sensoren aktivieren / deaktivieren&lt;br /&gt;
*Reparieren&lt;br /&gt;
*Batterien entladen&lt;br /&gt;
*Schilde aktivieren/deaktiviere/aufladen&lt;br /&gt;
*Reservebatterie aufladen&lt;br /&gt;
*Traktorstrahl ein- / ausschalten&lt;br /&gt;
*Beamen&lt;br /&gt;
*Verstecken&lt;br /&gt;
*Replikator aktivieren/deaktivieren&lt;br /&gt;
*Waren über Bord werfen&lt;br /&gt;
*Warpkern aktiveren/deaktivieren&lt;br /&gt;
*Wrackextraktoren&lt;br /&gt;
&lt;br /&gt;
Eine vollständige Auflistung aller Funktionen findet sich im [http://game.stne.net/ObjectExplorer.aspx?p=CShipManager Objekt-Explorer].&lt;br /&gt;
&lt;br /&gt;
Im folgenden wollen wir uns einige Funktionen genauer anschauen:&lt;br /&gt;
===Beamen===&lt;br /&gt;
Syntaxe:&lt;br /&gt;
 ShipManager.TransferiereZuSchiff(''Schiffid'', ''Menge'', EBeamRessource.''Ware'');&lt;br /&gt;
Hier musst du nun nurnoch den kursiven Text mit deinen Angaben ersetzten. Hier ein Beispiele:&lt;br /&gt;
 ShipManager.BenutzteSchiff(1);&lt;br /&gt;
 ShipManager.TransferiereZuSchiff(2, 20, EBeamRessource.Nahrung);&lt;br /&gt;
Natürlich kann man auch eine ganze Flotte beamen lassen, dazu ersetzt du ''ShipManager.BenutzteSchiff(1);'' durch ''ShipManager.BenutzteFlotte(1);'' Dann sieht das Script folgendermasen aus:&lt;br /&gt;
 ShipManager.BenutzteFlotte(1);&lt;br /&gt;
 ShipManager.TransferiereZuSchiff(2, 20, EBeamRessource.Nahrung);&lt;br /&gt;
&lt;br /&gt;
===Fliegen===&lt;br /&gt;
Bei der Syntaxe gibt es 2 Möglichkeiten, die eine für Spieler unter Level 8 oder mit [[Feature-Pack]], also mit Autopilot, und die andere für die Leute über Level 8 und ohne Feature-Pack, die Variante ohne Autopilot.&lt;br /&gt;
====Fliegen mit dem Autopiloten====&lt;br /&gt;
&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;'''''Nur für Spieler mit Feature-Pack oder unter Kolonisationslevel 8 möglich!'''''&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Der Befehl:&lt;br /&gt;
 ShipManager.FliegeZu(''xxx|yyy'');&lt;br /&gt;
Auch hier Gilt es wieder das kursive durch die eigenen Angaben zu ersetzten. Wie in folgendem Beispiel:&lt;br /&gt;
 ShipManager.BenutzteSchiff(1);&lt;br /&gt;
 ShipManager.FliegeZu('123|465');&lt;br /&gt;
oder mit dem Flottenbefehl:&lt;br /&gt;
 ShipManager.BenutzteFlotte(1);&lt;br /&gt;
 ShipManager.FliegeZu('123|465');&lt;br /&gt;
Mit deisem Befehl fliegt das Schiff zu einer belibigen Position, [[NPC|NPC-Gebiete]] ausgenommen, und umgeht dabei wie der Autopilot Energie-intensive Hindernisse, sowie solche die das Schiff oder die Crew Gefährden.&lt;br /&gt;
&lt;br /&gt;
====Fliegen ohne Autopilot====&lt;br /&gt;
Der Befehl hierzu sieht wie folgt aus:&lt;br /&gt;
 ShipManager.Fliege(''Strecke'', EShipRichtung.''Richtung'');&lt;br /&gt;
Auch hier ersetzt du die kursiven Worte mit deinen Angaben, ein Beispiel folgt:&lt;br /&gt;
 ShipManager.BenutzteSchiff(1);&lt;br /&gt;
 ShipManager.Fliege(5, EShipRichtung.Hoch);&lt;br /&gt;
 ShipManager.Fliege(8, EshipRichtung.Links);&lt;br /&gt;
oder wenn es eine ganze Flotte ist:&lt;br /&gt;
 ShipManager.BenutzteFlotte(1);&lt;br /&gt;
 ShipManager.Fliege(5, EShipRichtung.Hoch);&lt;br /&gt;
 ShipManager.Fliege(8, EshipRichtung.Links);&lt;br /&gt;
&lt;br /&gt;
===Schiffsystem nutzen===&lt;br /&gt;
kommt noch&lt;br /&gt;
&lt;br /&gt;
===Alternative zum Schiffsmanager: Schiffsaktion===&lt;br /&gt;
&lt;br /&gt;
Für Objekte des Typ's CMyFlotte und CMyShip kann über die Eigenschaft Aktion direkt auf die Funktionen des Schiffsmanagers zugegriffen werden.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;VAR Schiff AS CMyShip = new CMyShip( 4711 )&lt;br /&gt;
Schiff.Aktion.Abdocken()&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;VAR Flotte AS CMyFlotte = new CMyFlotte( 4711 )&lt;br /&gt;
Flotte.Aktion.Abdocken()&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Enumeration ist Alles==&lt;br /&gt;
kommt noch&lt;br /&gt;
&lt;br /&gt;
==Methoden==&lt;br /&gt;
&lt;br /&gt;
Öfters wiederkehrende Aufgaben können in Methoden zusammengefasst werden:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Function ShowKoords(x As Integer, y As Integer)&lt;br /&gt;
{&lt;br /&gt;
  WriteLine(CStr(x) + '|' + CStr(y));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Die Methode ShowKoords kann dann im Script folgendermaßen aufgerufen werden:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
ShowKoords(3, 4);&lt;br /&gt;
ShowKoords(ship.MapPosition.X,ship.MapPosition.Y);&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Wenn berechnete Werte von der Methode zurückgegeben werden sollen:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Function Distanz(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer) As Integer&lt;br /&gt;
{&lt;br /&gt;
  Var distanz As Integer;&lt;br /&gt;
  &lt;br /&gt;
  distanz = Math.Abs(x1 - x2) + Math.Abs(y1 - y2);&lt;br /&gt;
  Return distanz ;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
WriteLine(Distanz(1, 1, 5, 5));&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Einfache Typen werden immer 'ByVal' übergeben, d.h. die Werte werden als Kopie an die Methode übergeben und die entsprechenden Variablen im Script nicht verändert.&lt;br /&gt;
'ByRef' ist zwar in der Scriptengine vorgesehen und kann angegeben werden, ist aber derzeit ohne Funktion.&lt;br /&gt;
Objekte werden immer ByRef übergeben.&lt;br /&gt;
&lt;br /&gt;
==Klassen==&lt;br /&gt;
&lt;br /&gt;
In Klassen können Daten und Methoden in einem Objekt gekapselt werden:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
Class CKoords&lt;br /&gt;
{&lt;br /&gt;
  Var x As Integer;&lt;br /&gt;
  Var y As Integer;&lt;br /&gt;
  &lt;br /&gt;
  Function New(x As Integer, y As Integer)&lt;br /&gt;
  {&lt;br /&gt;
    This.x = x;&lt;br /&gt;
    This.y = y;&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  Function ToString() As String&lt;br /&gt;
  {&lt;br /&gt;
    Return (CStr(x) + '|' + CStr(y);&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  Function Distanz(koord As CKoords) As Integer&lt;br /&gt;
  {&lt;br /&gt;
    Return Math.Abs(x - koord.x) + Math.Abs(y - koord.y);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Var ko1 As New CKoords(3, 5);&lt;br /&gt;
Var ko2 As CKoords;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ko2 = New CKoords(8, 9);&lt;br /&gt;
WriteLine('Distanz von ' + ko1.ToString() + ' nach ' + ko2.ToString() + ': ' + CStr(ko1.Distanz(ko2)));&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Wichtig: Klassen brauchen immer eine Methode New(), sonst kann kein neues Objekt der Klasse generiert werden!&lt;br /&gt;
&lt;br /&gt;
==Autoren==&lt;br /&gt;
(hier dürfen sich diejenigen verewigen die hier min. ein Kapitel geschrieben haben [sonst kommt noch einer daher nur weil er nen Rechtschreibfehler verbessert hat ;)])&lt;br /&gt;
{|&lt;br /&gt;
!Nickname&lt;br /&gt;
!IG-id&lt;br /&gt;
!Kapitel&lt;br /&gt;
|-&lt;br /&gt;
|WiZz4Rd&lt;br /&gt;
|16475&lt;br /&gt;
|Kapitel 1, Kapitel 2, Kapitel 4&lt;br /&gt;
|-&lt;br /&gt;
|Stryke&lt;br /&gt;
|28885&lt;br /&gt;
|Vorwort, Kapitel 3, Kapitel 4&lt;br /&gt;
|-&lt;br /&gt;
|[[Spieler:Xenon|Xenon]]&lt;br /&gt;
|10127&lt;br /&gt;
|Korrektur &amp;amp; Überarbeitung Kapitel 1&lt;br /&gt;
|-&lt;br /&gt;
|Fling&lt;br /&gt;
|54865&lt;br /&gt;
|Kapitel 7, Kapitel 8&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Kategorie:Scripting-Hilfe|Anfängerkurs]]&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2011-02-07T12:18:22Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Explicit casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}.&lt;br /&gt;
This is best illustrated with a small example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
/* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
/* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
Var i As Integer;&lt;br /&gt;
For (i = 0 To 10) {&lt;br /&gt;
  WriteLine(i);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
Var i As Integer;&lt;br /&gt;
For (i = 10 To 0 Step -2) {&lt;br /&gt;
  WriteLine(i);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
Var MyShip As New CMyShip(123456);&lt;br /&gt;
Var Current As CShip;&lt;br /&gt;
For (Each Current In MyShip.SRS) {&lt;br /&gt;
  WriteLine(Current.Name);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
i = 0;&lt;br /&gt;
While (i &amp;lt;= 10) {&lt;br /&gt;
 WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
i = 0;&lt;br /&gt;
Do {&lt;br /&gt;
 WriteLine(i++);&lt;br /&gt;
}&lt;br /&gt;
While(i &amp;lt;= 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Breaking from loops ===&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
/* This prints 0 to 5 */&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/* This prints 0 to 5 */&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/* This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
   The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop. */&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
/* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
Function WriteHello() {&lt;br /&gt;
  WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
   Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
  If (NOT DoSomething) {&lt;br /&gt;
    Return;&lt;br /&gt;
  }&lt;br /&gt;
  WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This function prints the message passed to it as the first parameter */&lt;br /&gt;
Function WriteMsg(Msg As String) {&lt;br /&gt;
  WriteLine(Msg);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
  Return A &amp;gt; B;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
WriteHello(False);          // This will not do anything;&lt;br /&gt;
WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from a {{Code|CObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two ways will be explained in more detail below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Implicit casting ===&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of the desired type or passing it to a function that takes an argument of the desired type.&lt;br /&gt;
Some examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Explicit casting ===&lt;br /&gt;
We can also explicitly cast an object to a different type.&lt;br /&gt;
Sometimes this can save code, and sometimes it is required.&lt;br /&gt;
Not all casts can be done implicitly.&lt;br /&gt;
The general syntax is as follows: {{code|CType(Variable, [NewType])}}.&lt;br /&gt;
There are also shorthand versions available for convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:Code</id>
		<title>Template:Code</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:Code"/>
				<updated>2011-02-07T12:17:30Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&amp;lt;span style=&amp;quot;font-family:monospace;&amp;quot;&amp;gt;{{{1}}}&amp;lt;/span&amp;gt;&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
Use this template for small pieces of in-line code. Use pre tags for multi-line code.&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;{{code|Function DoStuff()}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
{{code|Function DoStuff()}}&lt;br /&gt;
[[Category:Templates]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:44:04Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}.&lt;br /&gt;
This is best illustrated with a small example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
/* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
/* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
Var i As Integer;&lt;br /&gt;
For (i = 0 To 10) {&lt;br /&gt;
  WriteLine(i);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
Var i As Integer;&lt;br /&gt;
For (i = 10 To 0 Step -2) {&lt;br /&gt;
  WriteLine(i);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
Var MyShip As New CMyShip(123456);&lt;br /&gt;
Var Current As CShip;&lt;br /&gt;
For (Each Current In MyShip.SRS) {&lt;br /&gt;
  WriteLine(Current.Name);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
i = 0;&lt;br /&gt;
While (i &amp;lt;= 10) {&lt;br /&gt;
 WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
i = 0;&lt;br /&gt;
Do {&lt;br /&gt;
 WriteLine(i++);&lt;br /&gt;
}&lt;br /&gt;
While(i &amp;lt;= 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Breaking from loops ===&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
/* This prints 0 to 5 */&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/* This prints 0 to 5 */&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/* This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
   The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop. */&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
/* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
Function WriteHello() {&lt;br /&gt;
  WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
   Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
  If (NOT DoSomething) {&lt;br /&gt;
    Return;&lt;br /&gt;
  }&lt;br /&gt;
  WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This function prints the message passed to it as the first parameter */&lt;br /&gt;
Function WriteMsg(Msg As String) {&lt;br /&gt;
  WriteLine(Msg);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
  Return A &amp;gt; B;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
WriteHello(False);          // This will not do anything;&lt;br /&gt;
WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from a {{Code|CObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two ways will be explained in more detail below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Implicit casting ===&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of the desired type or passing it to a function that takes an argument of the desired type.&lt;br /&gt;
Some examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Explicit casting ===&lt;br /&gt;
We can also explicitly cast an object to a different type.&lt;br /&gt;
Sometimes this can save code, and sometimes it is required.&lt;br /&gt;
Not all casts can be done implicitly.&lt;br /&gt;
The general syntax is as follows: {{code|CType(Variable, [NewType])}}.&lt;br /&gt;
There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:7px;&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:41:19Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Breaking from loops ===&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from a {{Code|CObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two ways will be explained in more detail below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Implicit casting ===&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of the desired type or passing it to a function that takes an argument of the desired type.&lt;br /&gt;
Some examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:10px;&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Explicit casting ===&lt;br /&gt;
We can also explicitly cast an object to a different type.&lt;br /&gt;
Sometimes this can save code, and sometimes it is required.&lt;br /&gt;
Not all casts can be done implicitly.&lt;br /&gt;
The general syntax is as follows: {{code|CType(Variable, [NewType])}}.&lt;br /&gt;
There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:10px;&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:39:41Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Breaking from loops ===&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from a {{Code|CObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two ways will be explained in more detail below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Implicit casting ===&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of the desired type or passing it to a function that takes an argument of the desired type. Some examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:3px;&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Explicit casting ===&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this can save code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto; padding:3px;&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:38:56Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Breaking from loops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Breaking from loops ===&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from a {{Code|CObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two ways will be explained in more detail below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Implicit casting ===&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of the desired type or passing it to a function that takes an argument of the desired type. Some examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Explicit casting ===&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this can save code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:38:33Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from a {{Code|CObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two ways will be explained in more detail below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Implicit casting ===&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of the desired type or passing it to a function that takes an argument of the desired type. Some examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Explicit casting ===&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this can save code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:38:07Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from a {{Code|CObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two ways will be explained in more detail below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
=== Implicit casting ===&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of the desired type or passing it to a function that takes an argument of the desired type. Some examples:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Explicit casting ===&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this can save code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:34:02Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;overflow:auto&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:31:27Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre style=&amp;quot;width: auto;&amp;quot;&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:30:20Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough&lt;br /&gt;
      to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:29:42Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);  // EBeamResource.Deuterium is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8, when you're experienced enough to know it is actually a metal alloy combined with acrylic polymers.&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:28:25Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType])}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8.&amp;quot;);  // EBeamResource.Plasteel is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:28:13Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable, [NewType)}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8.&amp;quot;);  // EBeamResource.Plasteel is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:27:41Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable|[NewType)}}. There are also shorthand versions available convenience:&lt;br /&gt;
&lt;br /&gt;
; {{code|CStr(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, String)}}&lt;br /&gt;
; {{code|CInt(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Integer)}}&lt;br /&gt;
; {{code|CBool(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Boolean)}}&lt;br /&gt;
; {{code|CDbl(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Double)}}&lt;br /&gt;
; {{code|CDate(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Date)}}&lt;br /&gt;
; {{code|CByte(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Byte)}}&lt;br /&gt;
; {{code|CShort(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Short)}}&lt;br /&gt;
; {{code|CSng(Variable)}}&lt;br /&gt;
* {{code|CType(Variable, Single)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8.&amp;quot;);  // EBeamResource.Plasteel is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
WriteLine(CStr(HashTable.Item(EBeamResource.Plasteel)).Length);           // Same as above, but less code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:26:14Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable|[NewType)}}. There are also shorthand versions available for frequently used casts.&lt;br /&gt;
; CStr(Variable)&lt;br /&gt;
* CType(Variable, String)&lt;br /&gt;
; CInt(Variable)&lt;br /&gt;
* CType(Variable, Integer)&lt;br /&gt;
; CBool(Variable)&lt;br /&gt;
* CType(Variable, Boolean);&lt;br /&gt;
; CDbl(Variable)&lt;br /&gt;
* CType(Variable, Double);&lt;br /&gt;
; CDate(Variable)&lt;br /&gt;
* CType(Variable, Date);&lt;br /&gt;
; CByte(Variable)&lt;br /&gt;
* CType(Variable, Byte);&lt;br /&gt;
; CShort(Variable)&lt;br /&gt;
* CType(Variable, Short);&lt;br /&gt;
; CSng(Variable)&lt;br /&gt;
* CType(Variable, Single);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8.&amp;quot;);  // EBeamResource.Plasteel is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:25:26Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Casting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;; // This is actually already an implicit cast from a String to an Object.&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Obj;   // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Obj);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Obj);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Obj.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Obj);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable|[NewType)}}. There are also shorthand versions available for frequently used casts.&lt;br /&gt;
* CStr(Variable)&lt;br /&gt;
;CType(Variable, String)&lt;br /&gt;
* CInt(Variable)&lt;br /&gt;
;CType(Variable, Integer)&lt;br /&gt;
* CBool(Variable)&lt;br /&gt;
;CType(Variable, Boolean);&lt;br /&gt;
* CDbl(Variable)&lt;br /&gt;
;CType(Variable, Double);&lt;br /&gt;
* CDate(Variable)&lt;br /&gt;
;CType(Variable, Date);&lt;br /&gt;
* CByte(Variable)&lt;br /&gt;
;CType(Variable, Byte);&lt;br /&gt;
* CShort(Variable)&lt;br /&gt;
;CType(Variable, Short);&lt;br /&gt;
* CSng(Variable)&lt;br /&gt;
;CType(Variable, Single);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8.&amp;quot;);  // EBeamResource.Plasteel is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T20:16:18Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;br /&gt;
&lt;br /&gt;
== Casting ==&lt;br /&gt;
&lt;br /&gt;
On occasion, it might be required to cast an object to a different type, for example after retrieving it from an {{Code|ObjectHashTable}}. There are two ways to go about this: implicit and explicit casting. These two are explained below. When casting objects to different types, it is important to remember that you can not simply cast an object to a random type. The compiler will not complain when you cast a CObjectHashTable to a CMyShip, but you will encounter a runtime exception if you try to execute the script. In general, you can always cast an object to any parent class and it's actual type. However, there are exceptions to this rule. For one, a lot of data types and classes can be cast to a String.&lt;br /&gt;
&lt;br /&gt;
Implicit casting is done by assigning an object to a variable of a the desired type or passing it to a function that takes an argument of the desired type. An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Implicit casting by assignment&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
WriteLine(Obj.Length);              // this won't work because the class Object does not have a Length member&lt;br /&gt;
Var StringObject As String = Thing; // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(StringObject.Length);     // Now we can access the Length member of the String class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Implicit casting by function call&lt;br /&gt;
Function Print(Message As String) {&lt;br /&gt;
  WriteLine(Message);&lt;br /&gt;
}&lt;br /&gt;
Function PrintLength(Message As String) {&lt;br /&gt;
  WriteLine(Message.Length); // This implicitly casts Message.Length (an Integer) to a String. Note we also did this in the code above&lt;br /&gt;
}&lt;br /&gt;
Var Obj As Object = &amp;quot;Hello world!&amp;quot;;&lt;br /&gt;
Print(Thing);                // Obj is implicitly cast to a String&lt;br /&gt;
WriteLine(Thing);            // Note that the Print function we defined is actually overkill here, this also implicitly casts Obj to a String.&lt;br /&gt;
WriteLine(Thing.Length);     // This won't work, Obj is of type Object, which does not have a Length member&lt;br /&gt;
PrintLength(Thing);          // This implicitly casts Obj to a String.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also explicitly cast an object to a different type. Sometimes this simply saves code, and sometimes it is required. Not all casts can be done implicitly. The general syntax is as follows: {{code|CType(Variable|[NewType)}}. There are also shorthand versions available for frequently used casts.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// Explicit casting&lt;br /&gt;
Var HashTable As New CObjectHashTable();&lt;br /&gt;
HashTable.Add(EBeamResource.Plasteel,   &amp;quot;Building material. Grows from trees until you reach level 8.&amp;quot;);  // EBeamResource.Plasteel is used as key in the hash table.&lt;br /&gt;
HashTable.Add(EBeamResource.Deuterium,  &amp;quot;Basic fuel. Raises your voice pitch when inhaled.&amp;quot;);&lt;br /&gt;
HashTable.Add(EBeamResource.AntiMatter, &amp;quot;Advanced fuel. Should NOT be inhaled.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
WriteLine(HashTable.Item(EBeamResource.Plasteel).Length);                 // This won't work, CObjectHashTable.Item() returns an Object, not a String.&lt;br /&gt;
WriteLine(CType(HashTable.Item(EBeamResource.Plasteel), String).Length);  // We now explicitly cast the return value to a String, so we can access the String class members.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T19:13:56Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Breaking from loops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T19:13:11Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Loops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Breaking from loops ==&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-11-04T19:12:50Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Loops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Breaking from loops ===&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to exit a loop early. This can be done using {{code|Exit For}}, {{code|Exit Do}} and {{code|Exit While}}. The example below should illustrate this. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
Var I As Integer = 0;&lt;br /&gt;
While(I &amp;lt; 10) {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit While;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5&lt;br /&gt;
I = 0;&lt;br /&gt;
Do {&lt;br /&gt;
  WriteLine(I);&lt;br /&gt;
  If (I = 5) {&lt;br /&gt;
    Exit Do;&lt;br /&gt;
  }&lt;br /&gt;
  I = I + 1;&lt;br /&gt;
} While (I &amp;lt; 10)&lt;br /&gt;
&lt;br /&gt;
// This prints 0 to 5, exactly once and NOT ten times.&lt;br /&gt;
// The inner loop breaks from the outer loop, in effect breaking from both the inner and outer loop.&lt;br /&gt;
Var J As Integer = 0;&lt;br /&gt;
For (J = 1 To 10) {&lt;br /&gt;
  I = 0;&lt;br /&gt;
  While(I &amp;lt; 10) {&lt;br /&gt;
    WriteLine(I);&lt;br /&gt;
    If (I = 5) {&lt;br /&gt;
      Exit For;&lt;br /&gt;
    }&lt;br /&gt;
    I = I + 1;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Operators</id>
		<title>Scripting:Operators</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Operators"/>
				<updated>2010-09-20T12:37:13Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Precedence */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
&lt;br /&gt;
== Table ==&lt;br /&gt;
In this section, a and b represent either literal values, object references or expressions evaluating to the appropriate type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== String operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Concatenation || a &amp;amp; b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Comparison operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Equals                   || a = b&lt;br /&gt;
|-&lt;br /&gt;
| References equal         || a Is b&lt;br /&gt;
|-&lt;br /&gt;
| Not equal to             || a &amp;lt;&amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than             || a &amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Less than                || a &amp;lt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than or equal to || a &amp;gt;= b&lt;br /&gt;
|-&lt;br /&gt;
| Less than or equal to    || a &amp;lt;= b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Arithmetic operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Assignment    || a = b&lt;br /&gt;
|-&lt;br /&gt;
| Addition       || a + b&lt;br /&gt;
|-&lt;br /&gt;
| Subtraction    || a - b&lt;br /&gt;
|-&lt;br /&gt;
| Multiplication || a * b&lt;br /&gt;
|-&lt;br /&gt;
| Division       || a / b&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || a++&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || ++a&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || a--&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || --a&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logical operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Logical NOT    || NOT a&lt;br /&gt;
|-&lt;br /&gt;
| Logical AND    || a AND b&lt;br /&gt;
|-&lt;br /&gt;
| Logical OR     || a OR b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Function call      || a()&lt;br /&gt;
|-&lt;br /&gt;
| Function reference || AddressOf a&lt;br /&gt;
|-&lt;br /&gt;
| Member (b of a)    || a.b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Precedence ==&lt;br /&gt;
&lt;br /&gt;
The exact operator precedence is unknown. However, the following order of precedence seems to apply:&lt;br /&gt;
&lt;br /&gt;
* Member, Function call&lt;br /&gt;
* Increment, Decrement&lt;br /&gt;
* Multiplication&lt;br /&gt;
* Addition, Subtraction&lt;br /&gt;
* Comparison&lt;br /&gt;
* Logical NOT&lt;br /&gt;
* Logical OR, Logical AND&lt;br /&gt;
* Assignment&lt;br /&gt;
&lt;br /&gt;
Operators with the same precedence seem to be applied from left to right. Keep in mind that the logical AND and OR are lazy. That is, if the left argument already dictates the outcome, the right argument is not evaluated. This is mainly important for arguments with side effects, such as function calls or the increment/decrement operators. It can also prevent referencing a NULL reference.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment operator v.s. equals operator ===&lt;br /&gt;
&lt;br /&gt;
The {{code | assignment}} operator and the {{code | equals}} operator use the same symbol. It depends on the context which operator is used. The {{code | assignment}} operator is used when a line of code follows the syntax {{code | Identifier {{=}} Value;}}. In all other cases, the {{code | equals}} operator is used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Increment and decrement operators ===&lt;br /&gt;
&lt;br /&gt;
There are two versions of the increment and decrement operators, namely the suffix and the prefix versions. The suffix versions increment or decrements the value hold by the identifier and then returns the old value. The prefix versions increment or decrement the value and return the result.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
 Var i As Integer = 5;&lt;br /&gt;
 WriteLine(i++); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(i--)  // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
 &lt;br /&gt;
 i = 5;&lt;br /&gt;
 WriteLine(++i); // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(--i); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== References equal ===&lt;br /&gt;
&lt;br /&gt;
The {{code | References equal}} operator returns true if both identifiers hold the same reference (or: point to the same object).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  Var i As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  Var j As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  WriteLine(i Is j); // false&lt;br /&gt;
 &lt;br /&gt;
  i = j;&lt;br /&gt;
  WriteLine(i Is j); // true&lt;br /&gt;
&lt;br /&gt;
For types defined as Struct in the Object Explorer, this operator will never return true. When assigning one struct variable to another, the value is copied instead of the reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== AddressOf ===&lt;br /&gt;
&lt;br /&gt;
The {{code | AddressOf}} operator actually returns a CDelegate instance.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 Var Delegate As CDelegate = AddressOf MyFunction;&lt;br /&gt;
 &lt;br /&gt;
 Function MyFunction() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello universe!&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Delegate.Invoke();  // Writes &amp;quot;Hello universe!&amp;quot;;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Operators</id>
		<title>Scripting:Operators</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Operators"/>
				<updated>2010-09-20T12:34:50Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
&lt;br /&gt;
== Table ==&lt;br /&gt;
In this section, a and b represent either literal values, object references or expressions evaluating to the appropriate type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== String operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Concatenation || a &amp;amp; b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Comparison operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Equals                   || a = b&lt;br /&gt;
|-&lt;br /&gt;
| References equal         || a Is b&lt;br /&gt;
|-&lt;br /&gt;
| Not equal to             || a &amp;lt;&amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than             || a &amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Less than                || a &amp;lt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than or equal to || a &amp;gt;= b&lt;br /&gt;
|-&lt;br /&gt;
| Less than or equal to    || a &amp;lt;= b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Arithmetic operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Assignment    || a = b&lt;br /&gt;
|-&lt;br /&gt;
| Addition       || a + b&lt;br /&gt;
|-&lt;br /&gt;
| Subtraction    || a - b&lt;br /&gt;
|-&lt;br /&gt;
| Multiplication || a * b&lt;br /&gt;
|-&lt;br /&gt;
| Division       || a / b&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || a++&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || ++a&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || a--&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || --a&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logical operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Logical NOT    || NOT a&lt;br /&gt;
|-&lt;br /&gt;
| Logical AND    || a AND b&lt;br /&gt;
|-&lt;br /&gt;
| Logical OR     || a OR b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Function call      || a()&lt;br /&gt;
|-&lt;br /&gt;
| Function reference || AddressOf a&lt;br /&gt;
|-&lt;br /&gt;
| Member (b of a)    || a.b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Precedence ==&lt;br /&gt;
&lt;br /&gt;
The exact operator precedence is unknown. However, the following order of precedence seems to apply:&lt;br /&gt;
&lt;br /&gt;
[*] Member, Function call&lt;br /&gt;
[*] Increment, Decrement&lt;br /&gt;
[*] Multiplication&lt;br /&gt;
[*] Addition, Subtraction&lt;br /&gt;
[*] Comparison&lt;br /&gt;
[*] Logical NOT&lt;br /&gt;
[*] Logical OR, Logical AND&lt;br /&gt;
[*] Assignment&lt;br /&gt;
&lt;br /&gt;
Operators with the same precedence seem to be applied from left to right. Keep in mind that the logical AND and OR are lazy. That is, if the left argument already dictates the outcome, the right argument is not evaluated. This is mainly important for arguments with side effects, such as function calls or the increment/decrement operators. It can also prevent referencing a NULL reference.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment operator v.s. equals operator ===&lt;br /&gt;
&lt;br /&gt;
The {{code | assignment}} operator and the {{code | equals}} operator use the same symbol. It depends on the context which operator is used. The {{code | assignment}} operator is used when a line of code follows the syntax {{code | Identifier {{=}} Value;}}. In all other cases, the {{code | equals}} operator is used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Increment and decrement operators ===&lt;br /&gt;
&lt;br /&gt;
There are two versions of the increment and decrement operators, namely the suffix and the prefix versions. The suffix versions increment or decrements the value hold by the identifier and then returns the old value. The prefix versions increment or decrement the value and return the result.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
 Var i As Integer = 5;&lt;br /&gt;
 WriteLine(i++); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(i--)  // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
 &lt;br /&gt;
 i = 5;&lt;br /&gt;
 WriteLine(++i); // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(--i); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== References equal ===&lt;br /&gt;
&lt;br /&gt;
The {{code | References equal}} operator returns true if both identifiers hold the same reference (or: point to the same object).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  Var i As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  Var j As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  WriteLine(i Is j); // false&lt;br /&gt;
 &lt;br /&gt;
  i = j;&lt;br /&gt;
  WriteLine(i Is j); // true&lt;br /&gt;
&lt;br /&gt;
For types defined as Struct in the Object Explorer, this operator will never return true. When assigning one struct variable to another, the value is copied instead of the reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== AddressOf ===&lt;br /&gt;
&lt;br /&gt;
The {{code | AddressOf}} operator actually returns a CDelegate instance.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 Var Delegate As CDelegate = AddressOf MyFunction;&lt;br /&gt;
 &lt;br /&gt;
 Function MyFunction() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello universe!&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Delegate.Invoke();  // Writes &amp;quot;Hello universe!&amp;quot;;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Abbreviations</id>
		<title>Abbreviations</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Abbreviations"/>
				<updated>2010-09-16T21:11:36Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menu}}&lt;br /&gt;
&lt;br /&gt;
==Abbreviations and Acronyms==&lt;br /&gt;
&lt;br /&gt;
This is a list of abbreviations and acronyms you might come across in the game itself or in chat, forum posts, etc.&lt;br /&gt;
&lt;br /&gt;
=Goods=&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| AM&lt;br /&gt;
| [[Antimatter]]&lt;br /&gt;
|-&lt;br /&gt;
| Cr / Creds&lt;br /&gt;
| [[Credits]]&lt;br /&gt;
|-&lt;br /&gt;
| Deut&lt;br /&gt;
| [[Deuterium]]&lt;br /&gt;
|-&lt;br /&gt;
| Dil / Dili&lt;br /&gt;
| [[Dilithium]]&lt;br /&gt;
|-&lt;br /&gt;
| Dur / Dura&lt;br /&gt;
| [[Duranium]]&lt;br /&gt;
|-&lt;br /&gt;
| E&lt;br /&gt;
| [[Energy]]&lt;br /&gt;
|-&lt;br /&gt;
| EP&lt;br /&gt;
| [[Escape Pods]]&lt;br /&gt;
|-&lt;br /&gt;
| Iri&lt;br /&gt;
| [[Iridium Ore]]&lt;br /&gt;
|-&lt;br /&gt;
| Iso / Isos&lt;br /&gt;
| [[Isolinear Chips]]&lt;br /&gt;
|-&lt;br /&gt;
| Lat / Lati&lt;br /&gt;
| [[Latinum]]&lt;br /&gt;
|-&lt;br /&gt;
| Nit / Nitri&lt;br /&gt;
| [[Nitrium]]&lt;br /&gt;
|-&lt;br /&gt;
| Ore&lt;br /&gt;
| [[Iridium Ore]]&lt;br /&gt;
|-&lt;br /&gt;
| Plast&lt;br /&gt;
| [[Plasteel]]&lt;br /&gt;
|-&lt;br /&gt;
| PT&lt;br /&gt;
| [[Photon Torpedoes]] / [[Plasma Torpedoes]]&lt;br /&gt;
|-&lt;br /&gt;
| QT&lt;br /&gt;
| [[Quantum Torpedoes]]&lt;br /&gt;
|-&lt;br /&gt;
| Sor / Sori&lt;br /&gt;
| [[Sorium]]&lt;br /&gt;
|-&lt;br /&gt;
| Trit / Trita&lt;br /&gt;
| [[Tritanium]]&lt;br /&gt;
|-&lt;br /&gt;
| Torps&lt;br /&gt;
| [[Torpedoes]] / [[Photon Torpedoes]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Ships==&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| Amat&lt;br /&gt;
| [[Amaterasu]]&lt;br /&gt;
|-&lt;br /&gt;
| Ana&lt;br /&gt;
| [[Anachrom]]&lt;br /&gt;
|-&lt;br /&gt;
| Dari&lt;br /&gt;
| [[Darinaya]]&lt;br /&gt;
|-&lt;br /&gt;
| FS&lt;br /&gt;
| [[Flagship]]&lt;br /&gt;
|-&lt;br /&gt;
| LDT, LRT&lt;br /&gt;
| [[Long distance transporter|Long distance/range transporter]]&lt;br /&gt;
|-&lt;br /&gt;
| Nausi&lt;br /&gt;
| [[Nausicaan]]&lt;br /&gt;
|-&lt;br /&gt;
| Orty&lt;br /&gt;
| [[Ortygia]]&lt;br /&gt;
|-&lt;br /&gt;
| Rubi&lt;br /&gt;
| [[Rubicon]]&lt;br /&gt;
|-&lt;br /&gt;
| SDT&lt;br /&gt;
| [[Short distance transporter|Short distance transporter]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Other=&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| AQ&lt;br /&gt;
| [[Alpha_Quadrant|Alpha Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| Aste / Asti&lt;br /&gt;
| [[Asteroid]] ''(See also: Roid)''&lt;br /&gt;
|-&lt;br /&gt;
| BPP&lt;br /&gt;
| [[BPP|Beam Protection Points]]&lt;br /&gt;
|-&lt;br /&gt;
| BQ&lt;br /&gt;
| [[Beta_Quadrant|Beta Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| BT&lt;br /&gt;
| [[Battletick|Battle Tick]]&lt;br /&gt;
|-&lt;br /&gt;
| Cardi&lt;br /&gt;
| [[Cardassian|Cardassian(s)]]&lt;br /&gt;
|-&lt;br /&gt;
| CF&lt;br /&gt;
| [[Cease Fire]]&lt;br /&gt;
|-&lt;br /&gt;
| Coords&lt;br /&gt;
| [[Coordinates]]&lt;br /&gt;
|-&lt;br /&gt;
| CS&lt;br /&gt;
| [[Combat-System|Combat System]]&lt;br /&gt;
|-&lt;br /&gt;
| Diplo&lt;br /&gt;
| [[Diplomacy]] / Diplomat&lt;br /&gt;
|-&lt;br /&gt;
| Dizzy&lt;br /&gt;
| [[Disruptor]]&lt;br /&gt;
|-&lt;br /&gt;
| DMZ&lt;br /&gt;
| [[DMZ|Demilitarized Zone]]&lt;br /&gt;
|-&lt;br /&gt;
| DQ&lt;br /&gt;
| [[Delta_Quadrant|Delta Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| EMP&lt;br /&gt;
| [[EMP|Electromagnetic Pulse]]&lt;br /&gt;
|-&lt;br /&gt;
| EPS&lt;br /&gt;
| [[EPS|Electro-plasma System]]&lt;br /&gt;
|-&lt;br /&gt;
| Exp&lt;br /&gt;
| [[Experience]] ''(See also: XP)''&lt;br /&gt;
|-&lt;br /&gt;
| Fed&lt;br /&gt;
| [[Federation]]&lt;br /&gt;
|-&lt;br /&gt;
| Fer / Ferengi&lt;br /&gt;
| [[Ferengi Trade Exchange]] or [[Ferengi]] (race)&lt;br /&gt;
|-&lt;br /&gt;
| FP&lt;br /&gt;
| [[Feature Pack]]&lt;br /&gt;
|-&lt;br /&gt;
| FR&lt;br /&gt;
| [[Flight range]]&lt;br /&gt;
|-&lt;br /&gt;
| FSM&lt;br /&gt;
| [[FSM|First-Step-Manager]]&lt;br /&gt;
|-&lt;br /&gt;
| FTE&lt;br /&gt;
| [[Ferengi Trade Exchange]] ''(See also: Fer / Ferengi)''&lt;br /&gt;
|-&lt;br /&gt;
| GQ&lt;br /&gt;
| [[Gamma_Quadrant|Gamma Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| Holo / Holo ops&lt;br /&gt;
| [[Holodeck Operators]]&lt;br /&gt;
|-&lt;br /&gt;
| HQ&lt;br /&gt;
| [[Headquarters]]&lt;br /&gt;
|-&lt;br /&gt;
| IGM&lt;br /&gt;
| [[In-game Message]] ''(See also: PM)''&lt;br /&gt;
|-&lt;br /&gt;
| IRC&lt;br /&gt;
| [[Internet Relay Chat]]&lt;br /&gt;
|-&lt;br /&gt;
| k&lt;br /&gt;
| 1,000 ''(k stands for kilo)''&lt;br /&gt;
|-&lt;br /&gt;
| LRS&lt;br /&gt;
| [[LRS|Long-Range-Sensors]]&lt;br /&gt;
|-&lt;br /&gt;
| lvl / lv&lt;br /&gt;
| Level&lt;br /&gt;
|-&lt;br /&gt;
| M&lt;br /&gt;
| M class or [[Standard planet]] ''(M stands for Minshara)''&lt;br /&gt;
|-&lt;br /&gt;
| MA&lt;br /&gt;
| [[Military Alliance]]&lt;br /&gt;
|-&lt;br /&gt;
| M/AM&lt;br /&gt;
| Matter/Antimatter&lt;br /&gt;
|-&lt;br /&gt;
| Mod&lt;br /&gt;
| [[Admins|Moderator]] / [[Moderate planet]]&lt;br /&gt;
|-&lt;br /&gt;
| NAP&lt;br /&gt;
| [[NAP|Non-Aggression-Pact]]&lt;br /&gt;
|-&lt;br /&gt;
| NCC&lt;br /&gt;
| Naval Construction Contract ''(ship designation)''&lt;br /&gt;
|-&lt;br /&gt;
| NPC&lt;br /&gt;
| [[NPC|Non-Player Characters]]&lt;br /&gt;
|-&lt;br /&gt;
| PM&lt;br /&gt;
| [[IGM|Personal Message]] ''(See also: IGM)''&lt;br /&gt;
|-&lt;br /&gt;
| PT&lt;br /&gt;
| [[Peace Treaty]]&lt;br /&gt;
|-&lt;br /&gt;
| Rep&lt;br /&gt;
| [[Reputation]]&lt;br /&gt;
|-&lt;br /&gt;
| Roid&lt;br /&gt;
| [[Asteroid]] ''(See also: Aste / Asti)''&lt;br /&gt;
|-&lt;br /&gt;
| RP&lt;br /&gt;
| [[RP|Roleplay]]&lt;br /&gt;
|-&lt;br /&gt;
| RPG&lt;br /&gt;
| [[RP|Roleplay Game]]&lt;br /&gt;
|-&lt;br /&gt;
| Sat / Sats&lt;br /&gt;
| [[Solar Satellite|Solar Satellite(s)]]&lt;br /&gt;
|-&lt;br /&gt;
| SCN&lt;br /&gt;
| [[SCN|Subspace Communication Network]]&lt;br /&gt;
|-&lt;br /&gt;
| SRS&lt;br /&gt;
| [[SRS|Short-Range-Sensors]]&lt;br /&gt;
|-&lt;br /&gt;
| SRT&lt;br /&gt;
| ''See: SDT''&lt;br /&gt;
|-&lt;br /&gt;
| SS&lt;br /&gt;
| [[Silverstar]]&lt;br /&gt;
|-&lt;br /&gt;
| SSCN&lt;br /&gt;
| [[SSCN|Secondary Subspace Communication Network]]&lt;br /&gt;
|-&lt;br /&gt;
| STNE&lt;br /&gt;
| SpaceTrek: The New Empire&lt;br /&gt;
|-&lt;br /&gt;
| SUP&lt;br /&gt;
| [[SUP|Federation Supply Station]]&lt;br /&gt;
|-&lt;br /&gt;
| Syndi&lt;br /&gt;
| [[Syndicate]]&lt;br /&gt;
|-&lt;br /&gt;
| TA&lt;br /&gt;
| [[Trade Agreement]]&lt;br /&gt;
|-&lt;br /&gt;
| Trit kit&lt;br /&gt;
| Tritanium kit&lt;br /&gt;
|-&lt;br /&gt;
| TS&lt;br /&gt;
| [[TS|TeamSpeak]]&lt;br /&gt;
|-&lt;br /&gt;
| USS&lt;br /&gt;
| United Space Ship&lt;br /&gt;
|-&lt;br /&gt;
| Vac / VAC&lt;br /&gt;
| Vacation / Vacation Mode&lt;br /&gt;
|-&lt;br /&gt;
| WC&lt;br /&gt;
| [[Warp_core|Warp Core]]&lt;br /&gt;
|-&lt;br /&gt;
| WCS&lt;br /&gt;
| [[Weather_Control_Station|Weather Control Station]]&lt;br /&gt;
|-&lt;br /&gt;
| WMD&lt;br /&gt;
| [[WMD|Weapon of Mass Destruction]]&lt;br /&gt;
|-&lt;br /&gt;
| XP&lt;br /&gt;
| [[Experience]] ''(See also: Exp)''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Abbreviations]]&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Abbreviations</id>
		<title>Abbreviations</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Abbreviations"/>
				<updated>2010-09-16T21:11:17Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Ships */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menu}}&lt;br /&gt;
&lt;br /&gt;
==Abbreviations and Acronyms==&lt;br /&gt;
&lt;br /&gt;
This is a list of abbreviations and acronyms you might come across in the game itself or in chat, forum posts, etc.&lt;br /&gt;
&lt;br /&gt;
=Goods=&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| AM&lt;br /&gt;
| [[Antimatter]]&lt;br /&gt;
|-&lt;br /&gt;
| Cr / Creds&lt;br /&gt;
| [[Credits]]&lt;br /&gt;
|-&lt;br /&gt;
| Deut&lt;br /&gt;
| [[Deuterium]]&lt;br /&gt;
|-&lt;br /&gt;
| Dil / Dili&lt;br /&gt;
| [[Dilithium]]&lt;br /&gt;
|-&lt;br /&gt;
| Dur / Dura&lt;br /&gt;
| [[Duranium]]&lt;br /&gt;
|-&lt;br /&gt;
| E&lt;br /&gt;
| [[Energy]]&lt;br /&gt;
|-&lt;br /&gt;
| EP&lt;br /&gt;
| [[Escape Pods]]&lt;br /&gt;
|-&lt;br /&gt;
| Iri&lt;br /&gt;
| [[Iridium Ore]]&lt;br /&gt;
|-&lt;br /&gt;
| Iso / Isos&lt;br /&gt;
| [[Isolinear Chips]]&lt;br /&gt;
|-&lt;br /&gt;
| Lat / Lati&lt;br /&gt;
| [[Latinum]]&lt;br /&gt;
|-&lt;br /&gt;
| Nit / Nitri&lt;br /&gt;
| [[Nitrium]]&lt;br /&gt;
|-&lt;br /&gt;
| Ore&lt;br /&gt;
| [[Iridium Ore]]&lt;br /&gt;
|-&lt;br /&gt;
| Plast&lt;br /&gt;
| [[Plasteel]]&lt;br /&gt;
|-&lt;br /&gt;
| PT&lt;br /&gt;
| [[Photon Torpedoes]] / [[Plasma Torpedoes]]&lt;br /&gt;
|-&lt;br /&gt;
| QT&lt;br /&gt;
| [[Quantum Torpedoes]]&lt;br /&gt;
|-&lt;br /&gt;
| Sor / Sori&lt;br /&gt;
| [[Sorium]]&lt;br /&gt;
|-&lt;br /&gt;
| Trit / Trita&lt;br /&gt;
| [[Tritanium]]&lt;br /&gt;
|-&lt;br /&gt;
| Torps&lt;br /&gt;
| [[Torpedoes]] / [[Photon Torpedoes]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Ships==&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| Amat&lt;br /&gt;
| [[Amaterasu]]&lt;br /&gt;
|-&lt;br /&gt;
| Ana&lt;br /&gt;
| [[Anachrom]]&lt;br /&gt;
|-&lt;br /&gt;
| Dari&lt;br /&gt;
| [[Darinaya]]&lt;br /&gt;
|-&lt;br /&gt;
| FS&lt;br /&gt;
| [[Flagship]]&lt;br /&gt;
|-&lt;br /&gt;
| LDT, LRT&lt;br /&gt;
| [[Long distance transporter|Long distance/range transporter]]&lt;br /&gt;
|-&lt;br /&gt;
| Nausi&lt;br /&gt;
| [[Nausicaan]]&lt;br /&gt;
|-&lt;br /&gt;
| Orty&lt;br /&gt;
| [[Ortygia]]&lt;br /&gt;
|-&lt;br /&gt;
| Rubi&lt;br /&gt;
| [[Rubicon]]&lt;br /&gt;
|-&lt;br /&gt;
| SDT&lt;br /&gt;
| [[Short distance transporter|Short distance transporter]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Other=&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| AQ&lt;br /&gt;
| [[Alpha_Quadrant|Alpha Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| Aste / Asti&lt;br /&gt;
| [[Asteroid]] ''(See also: Roid)''&lt;br /&gt;
|-&lt;br /&gt;
| BPP&lt;br /&gt;
| [[BPP|Beam Protection Points]]&lt;br /&gt;
|-&lt;br /&gt;
| BQ&lt;br /&gt;
| [[Beta_Quadrant|Beta Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| BT&lt;br /&gt;
| [[Battletick|Battle Tick]]&lt;br /&gt;
|-&lt;br /&gt;
| Cardi&lt;br /&gt;
| [[Cardassian|Cardassian(s)]]&lt;br /&gt;
|-&lt;br /&gt;
| CF&lt;br /&gt;
| [[Cease Fire]]&lt;br /&gt;
|-&lt;br /&gt;
| Coords&lt;br /&gt;
| [[Coordinates]]&lt;br /&gt;
|-&lt;br /&gt;
| CS&lt;br /&gt;
| [[Combat-System|Combat System]]&lt;br /&gt;
|-&lt;br /&gt;
| Diplo&lt;br /&gt;
| [[Diplomacy]] / Diplomat&lt;br /&gt;
|-&lt;br /&gt;
| Dizzy&lt;br /&gt;
| [[Disruptor]]&lt;br /&gt;
|-&lt;br /&gt;
| DMZ&lt;br /&gt;
| [[DMZ|Demilitarized Zone]]&lt;br /&gt;
|-&lt;br /&gt;
| DQ&lt;br /&gt;
| [[Delta_Quadrant|Delta Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| EMP&lt;br /&gt;
| [[EMP|Electromagnetic Pulse]]&lt;br /&gt;
|-&lt;br /&gt;
| EPS&lt;br /&gt;
| [[EPS|Electro-plasma System]]&lt;br /&gt;
|-&lt;br /&gt;
| Exp&lt;br /&gt;
| [[Experience]] ''(See also: XP)''&lt;br /&gt;
|-&lt;br /&gt;
| Fed&lt;br /&gt;
| [[Federation]]&lt;br /&gt;
|-&lt;br /&gt;
| Fer / Ferengi&lt;br /&gt;
| [[Ferengi Trade Exchange]] or [[Ferengi]] (race)&lt;br /&gt;
|-&lt;br /&gt;
| FP&lt;br /&gt;
| [[Feature Pack]]&lt;br /&gt;
|-&lt;br /&gt;
| FR&lt;br /&gt;
| [[Flight range]]&lt;br /&gt;
|-&lt;br /&gt;
| FSM&lt;br /&gt;
| [[FSM|First-Step-Manager]]&lt;br /&gt;
|-&lt;br /&gt;
| FTE&lt;br /&gt;
| [[Ferengi Trade Exchange]] ''(See also: Fer / Ferengi)''&lt;br /&gt;
|-&lt;br /&gt;
| GQ&lt;br /&gt;
| [[Gamma_Quadrant|Gamma Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| Holo / Holo ops&lt;br /&gt;
| [[Holodeck Operators]]&lt;br /&gt;
|-&lt;br /&gt;
| HQ&lt;br /&gt;
| [[Headquarters]]&lt;br /&gt;
|-&lt;br /&gt;
| IGM&lt;br /&gt;
| [[In-game Message]] ''(See also: PM)''&lt;br /&gt;
|-&lt;br /&gt;
| IRC&lt;br /&gt;
| [[Internet Relay Chat]]&lt;br /&gt;
|-&lt;br /&gt;
| k&lt;br /&gt;
| 1,000 ''(k stands for kilo)''&lt;br /&gt;
|-&lt;br /&gt;
| LRS&lt;br /&gt;
| [[LRS|Long-Range-Sensors]]&lt;br /&gt;
|-&lt;br /&gt;
| lvl / lv&lt;br /&gt;
| Level&lt;br /&gt;
|-&lt;br /&gt;
| M&lt;br /&gt;
| M class or [[Standard planet]] ''(M stands for Minshara)''&lt;br /&gt;
|-&lt;br /&gt;
| MA&lt;br /&gt;
| [[Military Alliance]]&lt;br /&gt;
|-&lt;br /&gt;
| M/AM&lt;br /&gt;
| Matter/Antimatter&lt;br /&gt;
|-&lt;br /&gt;
| Mod&lt;br /&gt;
| [[Admins|Moderator]] / [[Moderate planet]]&lt;br /&gt;
|-&lt;br /&gt;
| NAP&lt;br /&gt;
| [[NAP|Non-Aggression-Pact]]&lt;br /&gt;
|-&lt;br /&gt;
| NCC&lt;br /&gt;
| Naval Construction Contract ''(ship designation)''&lt;br /&gt;
|-&lt;br /&gt;
| NPC&lt;br /&gt;
| [[NPC|Non-Player Characters]]&lt;br /&gt;
|-&lt;br /&gt;
| PM&lt;br /&gt;
| [[IGM|Personal Message]] ''(See also: IGM)''&lt;br /&gt;
|-&lt;br /&gt;
| PT&lt;br /&gt;
| [[Peace Treaty]]&lt;br /&gt;
|-&lt;br /&gt;
| Rep&lt;br /&gt;
| [[Reputation]]&lt;br /&gt;
|-&lt;br /&gt;
| Roid&lt;br /&gt;
| [[Asteroid]] ''(See also: Aste / Asti)''&lt;br /&gt;
|-&lt;br /&gt;
| RP&lt;br /&gt;
| [[RP|Roleplay]]&lt;br /&gt;
|-&lt;br /&gt;
| RPG&lt;br /&gt;
| [[RP|Roleplay Game]]&lt;br /&gt;
|-&lt;br /&gt;
| Sat / Sats&lt;br /&gt;
| [[Solar Satellite|Solar Satellite(s)]]&lt;br /&gt;
|-&lt;br /&gt;
| SCN&lt;br /&gt;
| [[SCN|Subspace Communication Network]]&lt;br /&gt;
|-&lt;br /&gt;
| SRS&lt;br /&gt;
| [[SRS|Short-Range-Sensors]]&lt;br /&gt;
|-&lt;br /&gt;
| SRT&lt;br /&gt;
| ''See: SDT''&lt;br /&gt;
|-&lt;br /&gt;
| SS&lt;br /&gt;
| [[Silverstar]]&lt;br /&gt;
|-&lt;br /&gt;
| SSCN&lt;br /&gt;
| [[SSCN|Secondary Subspace Communication Network]]&lt;br /&gt;
|-&lt;br /&gt;
| STNE&lt;br /&gt;
| SpaceTrek: The New Empire&lt;br /&gt;
|-&lt;br /&gt;
| SUP&lt;br /&gt;
| [[SUP|Federation Supply Station]]&lt;br /&gt;
|-&lt;br /&gt;
| Syndi&lt;br /&gt;
| [[Syndicate]]&lt;br /&gt;
|-&lt;br /&gt;
| TA&lt;br /&gt;
| [[Trade Agreement]]&lt;br /&gt;
|-&lt;br /&gt;
| Trit kit&lt;br /&gt;
| Tritanium kit&lt;br /&gt;
|-&lt;br /&gt;
| TS&lt;br /&gt;
| [[TS|TeamSpeak]]&lt;br /&gt;
|-&lt;br /&gt;
| USS&lt;br /&gt;
| United Space Ship&lt;br /&gt;
|-&lt;br /&gt;
| Vac / VAC&lt;br /&gt;
| Vacation / Vacation Mode&lt;br /&gt;
|-&lt;br /&gt;
| WC&lt;br /&gt;
| [[Warp_core|Warp Core]]&lt;br /&gt;
|-&lt;br /&gt;
| WCS&lt;br /&gt;
| [[Weather_Control_Station|Weather Control Station]]&lt;br /&gt;
|-&lt;br /&gt;
| WMD&lt;br /&gt;
| [[WMD|Weapon of Mass Destruction]]&lt;br /&gt;
|-&lt;br /&gt;
| XP&lt;br /&gt;
| [[Experience]] ''(See also: Exp)''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Abbreviations]]&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Abbreviations</id>
		<title>Abbreviations</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Abbreviations"/>
				<updated>2010-09-16T21:10:56Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Other */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menu}}&lt;br /&gt;
&lt;br /&gt;
==Abbreviations and Acronyms==&lt;br /&gt;
&lt;br /&gt;
This is a list of abbreviations and acronyms you might come across in the game itself or in chat, forum posts, etc.&lt;br /&gt;
&lt;br /&gt;
=Goods=&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| AM&lt;br /&gt;
| [[Antimatter]]&lt;br /&gt;
|-&lt;br /&gt;
| Cr / Creds&lt;br /&gt;
| [[Credits]]&lt;br /&gt;
|-&lt;br /&gt;
| Deut&lt;br /&gt;
| [[Deuterium]]&lt;br /&gt;
|-&lt;br /&gt;
| Dil / Dili&lt;br /&gt;
| [[Dilithium]]&lt;br /&gt;
|-&lt;br /&gt;
| Dur / Dura&lt;br /&gt;
| [[Duranium]]&lt;br /&gt;
|-&lt;br /&gt;
| E&lt;br /&gt;
| [[Energy]]&lt;br /&gt;
|-&lt;br /&gt;
| EP&lt;br /&gt;
| [[Escape Pods]]&lt;br /&gt;
|-&lt;br /&gt;
| Iri&lt;br /&gt;
| [[Iridium Ore]]&lt;br /&gt;
|-&lt;br /&gt;
| Iso / Isos&lt;br /&gt;
| [[Isolinear Chips]]&lt;br /&gt;
|-&lt;br /&gt;
| Lat / Lati&lt;br /&gt;
| [[Latinum]]&lt;br /&gt;
|-&lt;br /&gt;
| Nit / Nitri&lt;br /&gt;
| [[Nitrium]]&lt;br /&gt;
|-&lt;br /&gt;
| Ore&lt;br /&gt;
| [[Iridium Ore]]&lt;br /&gt;
|-&lt;br /&gt;
| Plast&lt;br /&gt;
| [[Plasteel]]&lt;br /&gt;
|-&lt;br /&gt;
| PT&lt;br /&gt;
| [[Photon Torpedoes]] / [[Plasma Torpedoes]]&lt;br /&gt;
|-&lt;br /&gt;
| QT&lt;br /&gt;
| [[Quantum Torpedoes]]&lt;br /&gt;
|-&lt;br /&gt;
| Sor / Sori&lt;br /&gt;
| [[Sorium]]&lt;br /&gt;
|-&lt;br /&gt;
| Trit / Trita&lt;br /&gt;
| [[Tritanium]]&lt;br /&gt;
|-&lt;br /&gt;
| Torps&lt;br /&gt;
| [[Torpedoes]] / [[Photon Torpedoes]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Ships==&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| Amat&lt;br /&gt;
| [[Amaterasu]]&lt;br /&gt;
|-&lt;br /&gt;
| Ana&lt;br /&gt;
| [[Anachrom]]&lt;br /&gt;
|-&lt;br /&gt;
| Dari&lt;br /&gt;
| [[Darinaya]]&lt;br /&gt;
|-&lt;br /&gt;
| FS&lt;br /&gt;
| [[Flagship]]&lt;br /&gt;
|-&lt;br /&gt;
| LDT, LRT&lt;br /&gt;
| [[Long distance transporter|Long distance/range transporter]]&lt;br /&gt;
|-&lt;br /&gt;
| Nausi&lt;br /&gt;
| [[Nausicaan|Nausicaan(s)]]&lt;br /&gt;
|-&lt;br /&gt;
| Orty&lt;br /&gt;
| [[Ortygia]]&lt;br /&gt;
|-&lt;br /&gt;
| Rubi&lt;br /&gt;
| [[Rubicon]]&lt;br /&gt;
|-&lt;br /&gt;
| SDT&lt;br /&gt;
| [[Short distance transporter|Short distance transporter]]&lt;br /&gt;
|}&lt;br /&gt;
=Other=&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Abbreviation / Acronym&lt;br /&gt;
! Meaning&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| AQ&lt;br /&gt;
| [[Alpha_Quadrant|Alpha Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| Aste / Asti&lt;br /&gt;
| [[Asteroid]] ''(See also: Roid)''&lt;br /&gt;
|-&lt;br /&gt;
| BPP&lt;br /&gt;
| [[BPP|Beam Protection Points]]&lt;br /&gt;
|-&lt;br /&gt;
| BQ&lt;br /&gt;
| [[Beta_Quadrant|Beta Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| BT&lt;br /&gt;
| [[Battletick|Battle Tick]]&lt;br /&gt;
|-&lt;br /&gt;
| Cardi&lt;br /&gt;
| [[Cardassian|Cardassian(s)]]&lt;br /&gt;
|-&lt;br /&gt;
| CF&lt;br /&gt;
| [[Cease Fire]]&lt;br /&gt;
|-&lt;br /&gt;
| Coords&lt;br /&gt;
| [[Coordinates]]&lt;br /&gt;
|-&lt;br /&gt;
| CS&lt;br /&gt;
| [[Combat-System|Combat System]]&lt;br /&gt;
|-&lt;br /&gt;
| Diplo&lt;br /&gt;
| [[Diplomacy]] / Diplomat&lt;br /&gt;
|-&lt;br /&gt;
| Dizzy&lt;br /&gt;
| [[Disruptor]]&lt;br /&gt;
|-&lt;br /&gt;
| DMZ&lt;br /&gt;
| [[DMZ|Demilitarized Zone]]&lt;br /&gt;
|-&lt;br /&gt;
| DQ&lt;br /&gt;
| [[Delta_Quadrant|Delta Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| EMP&lt;br /&gt;
| [[EMP|Electromagnetic Pulse]]&lt;br /&gt;
|-&lt;br /&gt;
| EPS&lt;br /&gt;
| [[EPS|Electro-plasma System]]&lt;br /&gt;
|-&lt;br /&gt;
| Exp&lt;br /&gt;
| [[Experience]] ''(See also: XP)''&lt;br /&gt;
|-&lt;br /&gt;
| Fed&lt;br /&gt;
| [[Federation]]&lt;br /&gt;
|-&lt;br /&gt;
| Fer / Ferengi&lt;br /&gt;
| [[Ferengi Trade Exchange]] or [[Ferengi]] (race)&lt;br /&gt;
|-&lt;br /&gt;
| FP&lt;br /&gt;
| [[Feature Pack]]&lt;br /&gt;
|-&lt;br /&gt;
| FR&lt;br /&gt;
| [[Flight range]]&lt;br /&gt;
|-&lt;br /&gt;
| FSM&lt;br /&gt;
| [[FSM|First-Step-Manager]]&lt;br /&gt;
|-&lt;br /&gt;
| FTE&lt;br /&gt;
| [[Ferengi Trade Exchange]] ''(See also: Fer / Ferengi)''&lt;br /&gt;
|-&lt;br /&gt;
| GQ&lt;br /&gt;
| [[Gamma_Quadrant|Gamma Quadrant]]&lt;br /&gt;
|-&lt;br /&gt;
| Holo / Holo ops&lt;br /&gt;
| [[Holodeck Operators]]&lt;br /&gt;
|-&lt;br /&gt;
| HQ&lt;br /&gt;
| [[Headquarters]]&lt;br /&gt;
|-&lt;br /&gt;
| IGM&lt;br /&gt;
| [[In-game Message]] ''(See also: PM)''&lt;br /&gt;
|-&lt;br /&gt;
| IRC&lt;br /&gt;
| [[Internet Relay Chat]]&lt;br /&gt;
|-&lt;br /&gt;
| k&lt;br /&gt;
| 1,000 ''(k stands for kilo)''&lt;br /&gt;
|-&lt;br /&gt;
| LRS&lt;br /&gt;
| [[LRS|Long-Range-Sensors]]&lt;br /&gt;
|-&lt;br /&gt;
| lvl / lv&lt;br /&gt;
| Level&lt;br /&gt;
|-&lt;br /&gt;
| M&lt;br /&gt;
| M class or [[Standard planet]] ''(M stands for Minshara)''&lt;br /&gt;
|-&lt;br /&gt;
| MA&lt;br /&gt;
| [[Military Alliance]]&lt;br /&gt;
|-&lt;br /&gt;
| M/AM&lt;br /&gt;
| Matter/Antimatter&lt;br /&gt;
|-&lt;br /&gt;
| Mod&lt;br /&gt;
| [[Admins|Moderator]] / [[Moderate planet]]&lt;br /&gt;
|-&lt;br /&gt;
| NAP&lt;br /&gt;
| [[NAP|Non-Aggression-Pact]]&lt;br /&gt;
|-&lt;br /&gt;
| NCC&lt;br /&gt;
| Naval Construction Contract ''(ship designation)''&lt;br /&gt;
|-&lt;br /&gt;
| NPC&lt;br /&gt;
| [[NPC|Non-Player Characters]]&lt;br /&gt;
|-&lt;br /&gt;
| PM&lt;br /&gt;
| [[IGM|Personal Message]] ''(See also: IGM)''&lt;br /&gt;
|-&lt;br /&gt;
| PT&lt;br /&gt;
| [[Peace Treaty]]&lt;br /&gt;
|-&lt;br /&gt;
| Rep&lt;br /&gt;
| [[Reputation]]&lt;br /&gt;
|-&lt;br /&gt;
| Roid&lt;br /&gt;
| [[Asteroid]] ''(See also: Aste / Asti)''&lt;br /&gt;
|-&lt;br /&gt;
| RP&lt;br /&gt;
| [[RP|Roleplay]]&lt;br /&gt;
|-&lt;br /&gt;
| RPG&lt;br /&gt;
| [[RP|Roleplay Game]]&lt;br /&gt;
|-&lt;br /&gt;
| Sat / Sats&lt;br /&gt;
| [[Solar Satellite|Solar Satellite(s)]]&lt;br /&gt;
|-&lt;br /&gt;
| SCN&lt;br /&gt;
| [[SCN|Subspace Communication Network]]&lt;br /&gt;
|-&lt;br /&gt;
| SRS&lt;br /&gt;
| [[SRS|Short-Range-Sensors]]&lt;br /&gt;
|-&lt;br /&gt;
| SRT&lt;br /&gt;
| ''See: SDT''&lt;br /&gt;
|-&lt;br /&gt;
| SS&lt;br /&gt;
| [[Silverstar]]&lt;br /&gt;
|-&lt;br /&gt;
| SSCN&lt;br /&gt;
| [[SSCN|Secondary Subspace Communication Network]]&lt;br /&gt;
|-&lt;br /&gt;
| STNE&lt;br /&gt;
| SpaceTrek: The New Empire&lt;br /&gt;
|-&lt;br /&gt;
| SUP&lt;br /&gt;
| [[SUP|Federation Supply Station]]&lt;br /&gt;
|-&lt;br /&gt;
| Syndi&lt;br /&gt;
| [[Syndicate]]&lt;br /&gt;
|-&lt;br /&gt;
| TA&lt;br /&gt;
| [[Trade Agreement]]&lt;br /&gt;
|-&lt;br /&gt;
| Trit kit&lt;br /&gt;
| Tritanium kit&lt;br /&gt;
|-&lt;br /&gt;
| TS&lt;br /&gt;
| [[TS|TeamSpeak]]&lt;br /&gt;
|-&lt;br /&gt;
| USS&lt;br /&gt;
| United Space Ship&lt;br /&gt;
|-&lt;br /&gt;
| Vac / VAC&lt;br /&gt;
| Vacation / Vacation Mode&lt;br /&gt;
|-&lt;br /&gt;
| WC&lt;br /&gt;
| [[Warp_core|Warp Core]]&lt;br /&gt;
|-&lt;br /&gt;
| WCS&lt;br /&gt;
| [[Weather_Control_Station|Weather Control Station]]&lt;br /&gt;
|-&lt;br /&gt;
| WMD&lt;br /&gt;
| [[WMD|Weapon of Mass Destruction]]&lt;br /&gt;
|-&lt;br /&gt;
| XP&lt;br /&gt;
| [[Experience]] ''(See also: Exp)''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Abbreviations]]&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Player:Glest_Durnham/Generic_Constructions</id>
		<title>Player:Glest Durnham/Generic Constructions</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Player:Glest_Durnham/Generic_Constructions"/>
				<updated>2010-09-15T13:11:25Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Glest */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is Generic Constructions? =&lt;br /&gt;
&lt;br /&gt;
Generic Constructions is a programming company founded in the year 2315.&lt;br /&gt;
It provides scripts and subroutines for the Universal Scripting Engine as well as programs written for external engines.&lt;br /&gt;
All scripts released by Generic Constructions are free, although commissioned projects will be charged for.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Glest =&lt;br /&gt;
&lt;br /&gt;
The company is always lead by a Glest.&lt;br /&gt;
The current Glest is Durnham. Due to popular naming conventions of Terran settlers, Glest is often mistaken for a name.&lt;br /&gt;
It is however a title used to designate the highest authority in a company structure.&lt;br /&gt;
It is said to started as an acronym for Grand Leader and Every Such Thing, but no official sources can confirm or deny this. &lt;br /&gt;
It has grown to be the de-facto standard in technologically advanced companies.&lt;br /&gt;
&lt;br /&gt;
= Products and Services =&lt;br /&gt;
&lt;br /&gt;
Product releases and services provided by Generic Constructions are decentralized.&lt;br /&gt;
As such, all individual members are responsible for their own services, releases and updates.&lt;br /&gt;
However, tune in to subspace channel 417 for highlights regarding GC products and services.&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-09-11T10:41:03Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Loops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators#Increment and decrement operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-09-11T10:39:30Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Loops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a given limit is reached.&lt;br /&gt;
The initial value, limit and step can be negative and they can be floating point values.&lt;br /&gt;
If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression evaluates to {{code|True}}.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-09-11T10:36:50Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Loops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop types: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a certain value is reached. The initial value, limit and step can be negative values and (negative) floating point values. If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression results in True.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Interfaces</id>
		<title>Scripting:Interfaces</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Interfaces"/>
				<updated>2010-09-11T10:34:18Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* ColoniePortal */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
&lt;br /&gt;
Interfaces extend the possibilities of scripts by registering pre-defined variables.&lt;br /&gt;
For example, the {{code|Web}} interface provides two variables representing the HTTP request and response.&lt;br /&gt;
Using this interface, scripts can generate HTML output and get some information about the HTTP request.&lt;br /&gt;
&lt;br /&gt;
You can use an interface in a script by going to the settings tab in the script editor and ticking the interfaces you want to use.&lt;br /&gt;
You can also do it manually by adding this code at the top of the script:&lt;br /&gt;
 #UseInterface Web, ShipPortal  // a comma separated list of interfaces&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Web ==&lt;br /&gt;
The {{code|Web}} interface provides a script with the ability to generate HTML output and to read some information about the HTTP request. &lt;br /&gt;
&lt;br /&gt;
=== Registered variables ===&lt;br /&gt;
; {{code|Response As CWebResponse}}&lt;br /&gt;
: This represents the root element for your script's HTML response. By adding elements to Response, the script can generate HTML output.&lt;br /&gt;
; {{code|Request As CWebRequest}}&lt;br /&gt;
: This contains some data describing the HTTP request and some additional data added by STNE. Most notably, it contains the submitted form data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ShipPortal ==&lt;br /&gt;
The {{code|ShipPortal}} interface enables a script to be used as a ship portal.&lt;br /&gt;
Ship portals can be installed on a ship.&lt;br /&gt;
Anyone with a ship in the same sector can enter the ship's portal, and they will see the HTML output generated by the script.&lt;br /&gt;
By adding forms to the output you can also have the guest enter data which will be available to the script when the form is submitted.&lt;br /&gt;
See the 'Web' interface on details how to generate output.&lt;br /&gt;
&lt;br /&gt;
The interface provides a few variables exposing on which ship the portal is running, and the user and ship that entered the portal.&lt;br /&gt;
It also seems to include everything the {{code|Web}} interface provides.&lt;br /&gt;
However, it is recommended to also include the {{code|Web}} interface whenever you include this interface.&lt;br /&gt;
&lt;br /&gt;
=== Registered variables ===&lt;br /&gt;
; {{code|MyShip As CMyShip}}&lt;br /&gt;
: This is the ship the portal is running on.&lt;br /&gt;
; {{code|GuestShip As CShip}}&lt;br /&gt;
: This is the ship that the guest entered the portal from.&lt;br /&gt;
; {{code|GuestUser As CUser}}&lt;br /&gt;
: The user who entered the portal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ColoniePortal ==&lt;br /&gt;
The {{code|ColoniePortal}} interface enables a script to be used as a colony portal.&lt;br /&gt;
Colony portals can be installed on a colony.&lt;br /&gt;
Anyone with a ship in the same sector can enter the colony's portal, and they will see the HTML output generated by the script.&lt;br /&gt;
By adding forms to the output you can also have the guest enter data which will be available to the script when the form is submitted.&lt;br /&gt;
See the {{code|Web}} interface on details how to generate output.&lt;br /&gt;
&lt;br /&gt;
The interface provides a few variables exposing on which ship the portal is running, and the user and ship that entered the portal.&lt;br /&gt;
It also seems to include everything the {{code|Web}} interface provides.&lt;br /&gt;
However, it is recommended to also include the {{code|Web}} interface whenever you include this interface.&lt;br /&gt;
&lt;br /&gt;
=== Registered variables ===&lt;br /&gt;
; {{code|MyColony As CMyColony}}&lt;br /&gt;
: This is the colony the portal is running on.&lt;br /&gt;
; {{code|GuestShip As CShip}}&lt;br /&gt;
: This is the ship that the guest entered the portal from.&lt;br /&gt;
; {{code|GuestUser As CUser}}&lt;br /&gt;
: The user who entered the portal.&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:Code</id>
		<title>Template:Code</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:Code"/>
				<updated>2010-09-10T16:53:50Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&amp;lt;span style=&amp;quot;font-family:monospace;&amp;quot;&amp;gt;{{{1}}}&amp;lt;/span&amp;gt;&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
Use this template for small pieces of in-line code. Use pre tags for multi-line code.&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;{{code|Function DoStuff()}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
{{code|Function DoStuff()}}&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Contents</id>
		<title>Scripting:Contents</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Contents"/>
				<updated>2010-09-10T16:53:16Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: Redirected page to Category:Scripting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[:Category:Scripting]]&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Interfaces</id>
		<title>Scripting:Interfaces</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Interfaces"/>
				<updated>2010-09-10T16:51:55Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
&lt;br /&gt;
Interfaces extend the possibilities of scripts by registering pre-defined variables.&lt;br /&gt;
For example, the {{code|Web}} interface provides two variables representing the HTTP request and response.&lt;br /&gt;
Using this interface, scripts can generate HTML output and get some information about the HTTP request.&lt;br /&gt;
&lt;br /&gt;
You can use an interface in a script by going to the settings tab in the script editor and ticking the interfaces you want to use.&lt;br /&gt;
You can also do it manually by adding this code at the top of the script:&lt;br /&gt;
 #UseInterface Web, ShipPortal  // a comma separated list of interfaces&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Web ==&lt;br /&gt;
The {{code|Web}} interface provides a script with the ability to generate HTML output and to read some information about the HTTP request. &lt;br /&gt;
&lt;br /&gt;
=== Registered variables ===&lt;br /&gt;
; {{code|Response As CWebResponse}}&lt;br /&gt;
: This represents the root element for your script's HTML response. By adding elements to Response, the script can generate HTML output.&lt;br /&gt;
; {{code|Request As CWebRequest}}&lt;br /&gt;
: This contains some data describing the HTTP request and some additional data added by STNE. Most notably, it contains the submitted form data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ShipPortal ==&lt;br /&gt;
The {{code|ShipPortal}} interface enables a script to be used as a ship portal.&lt;br /&gt;
Ship portals can be installed on a ship.&lt;br /&gt;
Anyone with a ship in the same sector can enter the ship's portal, and they will see the HTML output generated by the script.&lt;br /&gt;
By adding forms to the output you can also have the guest enter data which will be available to the script when the form is submitted.&lt;br /&gt;
See the 'Web' interface on details how to generate output.&lt;br /&gt;
&lt;br /&gt;
The interface provides a few variables exposing on which ship the portal is running, and the user and ship that entered the portal.&lt;br /&gt;
It also seems to include everything the {{code|Web}} interface provides.&lt;br /&gt;
However, it is recommended to also include the {{code|Web}} interface whenever you include this interface.&lt;br /&gt;
&lt;br /&gt;
=== Registered variables ===&lt;br /&gt;
; {{code|MyShip As CMyShip}}&lt;br /&gt;
: This is the ship the portal is running on.&lt;br /&gt;
; {{code|GuestShip As CShip}}&lt;br /&gt;
: This is the ship that the guest entered the portal from.&lt;br /&gt;
; {{code|GuestUser As CUser}}&lt;br /&gt;
: The user who entered the portal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ColoniePortal ==&lt;br /&gt;
The {{code|ColoniePortal}} interface enables a script to be used as a ship portal.&lt;br /&gt;
Colony portals can be installed on a ship.&lt;br /&gt;
Anyone with a ship in the same sector can enter the colony's portal, and they will see the HTML output generated by the script.&lt;br /&gt;
By adding forms to the output you can also have the guest enter data which will be available to the script when the form is submitted.&lt;br /&gt;
See the {{code|Web}} interface on details how to generate output.&lt;br /&gt;
&lt;br /&gt;
The interface provides a few variables exposing on which ship the portal is running, and the user and ship that entered the portal.&lt;br /&gt;
It also seems to include everything the {{code|Web}} interface provides.&lt;br /&gt;
However, it is recommended to also include the {{code|Web}} interface whenever you include this interface.&lt;br /&gt;
&lt;br /&gt;
=== Registered variables ===&lt;br /&gt;
; {{code|MyColony As CMyColony}}&lt;br /&gt;
: This is the colony the portal is running on.&lt;br /&gt;
; {{code|GuestShip As CShip}}&lt;br /&gt;
: This is the ship that the guest entered the portal from.&lt;br /&gt;
; {{code|GuestUser As CUser}}&lt;br /&gt;
: The user who entered the portal.&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:ScriptingMenu</id>
		<title>Template:ScriptingMenu</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:ScriptingMenu"/>
				<updated>2010-09-10T16:51:35Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menubar| [[Scripting:Main page|Main]] {{!}} [[Scripting:Syntax|Syntax]] {{!}} [[Scripting:Operators|Operators]] {{!}} [[Scripting:Interfaces|Interfaces]] {{!}} [[:Category:Scripting|Contents]] {{!}} [[Scripting:API|API Reference]] {{!}} [[Scripting:Index|Index]]}}&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:ApiMenu</id>
		<title>Template:ApiMenu</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:ApiMenu"/>
				<updated>2010-09-10T16:50:44Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menubar| [[Scripting:Main page|Scripting Portal]] {{!}} [[Scripting:Contents|Contents]] {{!}} [[Scripting:API|API Reference]] {{!}} [[Scripting:Index|Index]]}}&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Category:Scripting</id>
		<title>Category:Scripting</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Category:Scripting"/>
				<updated>2010-09-10T16:50:18Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ScriptingMenu}}&lt;br /&gt;
&lt;br /&gt;
This category contains articles related to scripting.&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Category:Scripting</id>
		<title>Category:Scripting</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Category:Scripting"/>
				<updated>2010-09-10T16:50:09Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{ScriptingMenu}}&lt;br /&gt;
&lt;br /&gt;
This category contains pages related to scripting.&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:ScriptingMenu</id>
		<title>Template:ScriptingMenu</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:ScriptingMenu"/>
				<updated>2010-09-10T16:48:50Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menubar| [[Scripting:Main page|Main]] {{!}} [[Scripting:Syntax|Syntax]] {{!}} [[Scripting:Operators|Operators]] {{!}} [[:Category:Scripting|Contents]] {{!}} [[Scripting:API|API Reference]] {{!}} [[Scripting:Index|Index]]}}&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:ScriptingMenu</id>
		<title>Template:ScriptingMenu</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:ScriptingMenu"/>
				<updated>2010-09-10T16:48:23Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menubar| [[Scripting:Main page|Main]] {{!}} [[Scripting:Syntax|Syntax]] {{!}} [[Scripting:Operators|Operators]] {{!}} [[:Category:Scripting|Contents]] {{!}} [[Scripting:API|API Reference]] {{!}} [[Scripting:Index|Index]]}}&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:Scripting]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Operators</id>
		<title>Scripting:Operators</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Operators"/>
				<updated>2010-09-10T16:47:21Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
&lt;br /&gt;
== Table ==&lt;br /&gt;
In this section, a and b represent either literal values, object references or expressions evaluating to the appropriate type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== String operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Concatenation || a &amp;amp; b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Comparison operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Equals                   || a = b&lt;br /&gt;
|-&lt;br /&gt;
| References equal         || a Is b&lt;br /&gt;
|-&lt;br /&gt;
| Not equal to             || a &amp;lt;&amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than             || a &amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Less than                || a &amp;lt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than or equal to || a &amp;gt;= b&lt;br /&gt;
|-&lt;br /&gt;
| Less than or equal to    || a &amp;lt;= b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Arithmetic operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Assignment    || a = b&lt;br /&gt;
|-&lt;br /&gt;
| Addition       || a + b&lt;br /&gt;
|-&lt;br /&gt;
| Subtraction    || a - b&lt;br /&gt;
|-&lt;br /&gt;
| Multiplication || a * b&lt;br /&gt;
|-&lt;br /&gt;
| Division       || a / b&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || a++&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || ++a&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || a--&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || --a&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logical operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Logical NOT    || NOT a&lt;br /&gt;
|-&lt;br /&gt;
| Logical AND    || a AND b&lt;br /&gt;
|-&lt;br /&gt;
| Logical OR     || a OR b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Function call      || a()&lt;br /&gt;
|-&lt;br /&gt;
| Function reference || AddressOf a&lt;br /&gt;
|-&lt;br /&gt;
| Member b of a      || a.b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment operator v.s. equals operator ===&lt;br /&gt;
&lt;br /&gt;
The {{code | assignment}} operator and the {{code | equals}} operator use the same symbol. It depends on the context which operator is used. The {{code | assignment}} operator is used when a line of code follows the syntax {{code | Identifier {{=}} Value;}}. In all other cases, the {{code | equals}} operator is used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Increment and decrement operators ===&lt;br /&gt;
&lt;br /&gt;
There are two versions of the increment and decrement operators, namely the suffix and the prefix versions. The suffix versions increment or decrements the value hold by the identifier and then returns the old value. The prefix versions increment or decrement the value and return the result.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
 Var i As Integer = 5;&lt;br /&gt;
 WriteLine(i++); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(i--)  // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
 &lt;br /&gt;
 i = 5;&lt;br /&gt;
 WriteLine(++i); // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(--i); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== References equal ===&lt;br /&gt;
&lt;br /&gt;
The {{code | References equal}} operator returns true if both identifiers hold the same reference (or: point to the same object).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  Var i As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  Var j As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  WriteLine(i Is j); // false&lt;br /&gt;
 &lt;br /&gt;
  i = j;&lt;br /&gt;
  WriteLine(i Is j); // true&lt;br /&gt;
&lt;br /&gt;
For types defined as Struct in the Object Explorer, this operator will never return true. When assigning one struct variable to another, the value is copied instead of the reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== AddressOf ===&lt;br /&gt;
&lt;br /&gt;
The {{code | AddressOf}} operator actually returns a CDelegate instance.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 Var Delegate As CDelegate = AddressOf MyFunction;&lt;br /&gt;
 &lt;br /&gt;
 Function MyFunction() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello universe!&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Delegate.Invoke();  // Writes &amp;quot;Hello universe!&amp;quot;;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-09-10T16:47:02Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop statements: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a certain value is reached. The initial value, limit and step can be negative values and (negative) floating point values. If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression results in True.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Main_page</id>
		<title>Scripting:Main page</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Main_page"/>
				<updated>2010-09-10T16:46:52Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
{{CreateScriptingArticle}}&lt;br /&gt;
&lt;br /&gt;
This section of the Wiki is intended to document the scripting engine found in the game. Most scripting related pages in STNE can be found from the main menu trough Database -&amp;gt; Scripting.&lt;br /&gt;
&lt;br /&gt;
=== Topics: ===&lt;br /&gt;
* [[Scripting:Syntax|Syntax]]&lt;br /&gt;
* [[Scripting:Operators|Operators]]&lt;br /&gt;
* [[Scripting:Interfaces|Interfaces]]&lt;br /&gt;
&lt;br /&gt;
* [[Scripting:Basic course|Basic course]] (untranslated)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:ScriptingMenu</id>
		<title>Template:ScriptingMenu</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:ScriptingMenu"/>
				<updated>2010-09-10T16:46:29Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Menubar| [[Scripting:Main page|Main]] {{!}} [[Scripting:Syntax|Syntax]] {{!}} [[Scripting:Operators|Operators]] {{!}} [[Scripting:Contents|Contents]] {{!}} [[Scripting:API|API Reference]] {{!}} [[Scripting:Index|Index]]}}&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:Scripting]]&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Template:Code</id>
		<title>Template:Code</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Template:Code"/>
				<updated>2010-09-10T16:44:00Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;&amp;lt;span style=&amp;quot;font-family:monospace;&amp;quot;&amp;gt;{{{1}}}&amp;lt;/span&amp;gt;&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
Use this template for small pieces of in-line code. Use pre tags for multi-line code.&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
&amp;lt;pre&amp;gt;{{code|Function DoStuff()}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
{{code|Function DoStuff()}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-09-10T16:42:27Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting|Syntax]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon.&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop statements: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a certain value is reached. The initial value, limit and step can be negative values and (negative) floating point values. If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression results in True.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Syntax</id>
		<title>Scripting:Syntax</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Syntax"/>
				<updated>2010-09-10T16:41:57Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting|Syntax]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
This page describes the syntax of the STNE scripting engine.&lt;br /&gt;
&lt;br /&gt;
As with C style languages, function calls, variable declarations and assignments have to be terminated by a semicolon (;).&lt;br /&gt;
&lt;br /&gt;
== Variable declaration ==&lt;br /&gt;
Variables are declared using the syntax {{code|Var [VarName] As [VarType]}}. This is best illustrated with a small example:&lt;br /&gt;
 Var WelcomeMessage As String; // Declares a variable named 'WelcomeMessage' of type String&lt;br /&gt;
 Var DataTable As CTable;      // Declares a variable named 'DataTable' of type CTable&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 /* It is also possible to immediately assign a value when declaring variables */&lt;br /&gt;
 &lt;br /&gt;
 Var WelcomeMessage As String = &amp;quot;Hello galaxy!&amp;quot;; // Declares a string and assigns it a value&lt;br /&gt;
 Var DataTable      As CTable = New CTable();    // Declares a variable and assigns a newly created CTable to it&lt;br /&gt;
 Var InfoTable      As New CTable();             // Also declares a variable and assigns a newly created CTable to it, but with less code&lt;br /&gt;
&lt;br /&gt;
== Conditional statements ==&lt;br /&gt;
It is possible to wrap code in conditional code blocks by using {{code|If}}, {{code|Else}} and {{code|ElseIf}} statements.&lt;br /&gt;
{{code|If}} and {{code|ElseIf}} statements are followed by a boolean expression between round brackets.&lt;br /&gt;
Code blocks following the {{code|If}}/{{code|Else}}/{{code|ElseIf}} statements have to be wrapped in curly brackets.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 If (x &amp;lt;= 5) {&lt;br /&gt;
   WriteLine(&amp;quot;Five or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 ElseIf (x &amp;lt;= 10) {&lt;br /&gt;
   WriteLine(&amp;quot;More than five.&amp;quot;);&lt;br /&gt;
   WriteLine(&amp;quot;Ten or less.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 Else {&lt;br /&gt;
   WriteLine(&amp;quot;More than ten.&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
There are a few kind of loop statements: {{code|For}}, {{code|For Each}}, {{code|While}} and {{code|Do...While}} loops.&lt;br /&gt;
They work similar to the equally named loops in other programming languages.&lt;br /&gt;
&lt;br /&gt;
The {{code|For}} loop will increment a specified counter by a given step until a certain value is reached. The initial value, limit and step can be negative values and (negative) floating point values. If a step is omitted, the default value of 1 will be used.&lt;br /&gt;
&lt;br /&gt;
The {{code|For Each}} loop iterates all elements of a class implementing the interface {{code|ICollection}}.&lt;br /&gt;
You can recognize classes implementing this interface by the few methods in the interface.&lt;br /&gt;
Note that using {{code|For Each}} on dictionaries and hash tables will loop the {{code|DictionaryEntry}} structs in the dictionary and not the keys or values.&lt;br /&gt;
You can however loop {{code|Dictionary.Keys}} or {{code|Dictionary.Values}} if you are only interested in either the keys or the values.&lt;br /&gt;
If you need both the keys and values, it is recommended to loop the {{code|DictionaryEntry}} structs.&lt;br /&gt;
&lt;br /&gt;
The {{code|While}} and {{code|Do...While}} loops continue to loop while a boolean expression results in True.&lt;br /&gt;
The difference between the {{code|While}} and {{code|Do...While}} loops is when the boolean expression is evaluated.&lt;br /&gt;
{{code|While}} loops check the expression at the beginning of each iteration, {{code|Do...While}} loops check the expression at the end of each iteration.&lt;br /&gt;
As a result, {{code|Do...While}} loops are always executed at least once.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 0 To 10) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print all even numbers from 10 to 0. 10 and 0 included, in reverse order. */&lt;br /&gt;
 Var i As Integer;&lt;br /&gt;
 For (i = 10 To 0 Step -2) {&lt;br /&gt;
   WriteLine(i);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print the name of each ship in the SRS report of the ship with NCC 123456 */&lt;br /&gt;
 Var MyShip As New CMyShip(123456);&lt;br /&gt;
 Var Current As CShip;&lt;br /&gt;
 For (Each Current In MyShip.SRS) {&lt;br /&gt;
   WriteLine(Current.Name);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 10. 0 and 10 included. */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 While (i &amp;lt;= 10) {&lt;br /&gt;
  WriteLine(i++);    // i++ increases i by one and returns the old value, see [[Scripting:Operators|Operators]] for details.&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This will print each number from 0 to 11. 0 and 11 included! */&lt;br /&gt;
 i = 0;&lt;br /&gt;
 Do {&lt;br /&gt;
  WriteLine(i++);&lt;br /&gt;
 }&lt;br /&gt;
 While(i &amp;lt;= 10)&lt;br /&gt;
&lt;br /&gt;
== Functions (user defined) ==&lt;br /&gt;
&lt;br /&gt;
You may define your own functions using the following syntax: {{code|Function [Name]([Param1Name] As [Param1Type], ...) As [ReturnType]}} followed by a code block wrapped in curly braces.&lt;br /&gt;
Functions can have zero or more parameters.&lt;br /&gt;
The return type is optional.&lt;br /&gt;
You can define multiple functions with the same name, as long as they have a different amount of parameters.&lt;br /&gt;
Different types of parameters is not enough for user defined functions.&lt;br /&gt;
Functions can return a value with the keyword {{code|Return [value];}}.&lt;br /&gt;
If a function has no return type, {{code|Return;}} will exit the function.&lt;br /&gt;
&lt;br /&gt;
A few examples:&lt;br /&gt;
 /* This function simply prints &amp;quot;Hello&amp;quot; */&lt;br /&gt;
 Function WriteHello() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* It is possible to defined multiple functions with the same name, if they have a different amount of parameters.&lt;br /&gt;
    Functions without return type can use Return to quickly exit the function. */&lt;br /&gt;
 Function WriteHello(DoSomething As Boolean) {&lt;br /&gt;
   If (NOT DoSomething) {&lt;br /&gt;
     Return;&lt;br /&gt;
   }&lt;br /&gt;
   WriteLine(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function prints the message passed to it as the first parameter */&lt;br /&gt;
 Function WriteMsg(Msg As String) {&lt;br /&gt;
   WriteLine(Msg);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* This function returns True if A is higher than B, False otherwise */&lt;br /&gt;
 Function isHigher(A As Integer, B As Integer) As Boolean {&lt;br /&gt;
   Return A &amp;gt; B;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 WriteHello();               // This will now print &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 WriteHello(True);           // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteHello(False);          // This will not do anything;&lt;br /&gt;
 WriteMsg(&amp;quot;Hello&amp;quot;);          // This also prints &amp;quot;Hello&amp;quot;&lt;br /&gt;
 WriteLine(isHigher(10, 5)); // This will print &amp;quot;True&amp;quot; (the Boolean return value is implicitly cast to a String)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Main_page</id>
		<title>Scripting:Main page</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Main_page"/>
				<updated>2010-09-10T16:39:44Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Scripting|Main page]]&lt;br /&gt;
{{ScriptingMenu}}&lt;br /&gt;
{{CreateScriptingArticle}}&lt;br /&gt;
&lt;br /&gt;
This section of the Wiki is intended to document the scripting engine found in the game. Most scripting related pages in STNE can be found from the main menu trough Database -&amp;gt; Scripting.&lt;br /&gt;
&lt;br /&gt;
=== Topics: ===&lt;br /&gt;
* [[Scripting:Syntax|Syntax]]&lt;br /&gt;
* [[Scripting:Operators|Operators]]&lt;br /&gt;
* [[Scripting:Interfaces|Interfaces]]&lt;br /&gt;
&lt;br /&gt;
* [[Scripting:Basic course|Basic course]] (untranslated)&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Operators</id>
		<title>Scripting:Operators</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Operators"/>
				<updated>2010-09-10T16:39:17Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Table ==&lt;br /&gt;
In this section, a and b represent either literal values, object references or expressions evaluating to the appropriate type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== String operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Concatenation || a &amp;amp; b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Comparison operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Equals                   || a = b&lt;br /&gt;
|-&lt;br /&gt;
| References equal         || a Is b&lt;br /&gt;
|-&lt;br /&gt;
| Not equal to             || a &amp;lt;&amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than             || a &amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Less than                || a &amp;lt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than or equal to || a &amp;gt;= b&lt;br /&gt;
|-&lt;br /&gt;
| Less than or equal to    || a &amp;lt;= b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Arithmetic operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Assignment    || a = b&lt;br /&gt;
|-&lt;br /&gt;
| Addition       || a + b&lt;br /&gt;
|-&lt;br /&gt;
| Subtraction    || a - b&lt;br /&gt;
|-&lt;br /&gt;
| Multiplication || a * b&lt;br /&gt;
|-&lt;br /&gt;
| Division       || a / b&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || a++&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || ++a&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || a--&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || --a&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logical operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Logical NOT    || NOT a&lt;br /&gt;
|-&lt;br /&gt;
| Logical AND    || a AND b&lt;br /&gt;
|-&lt;br /&gt;
| Logical OR     || a OR b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Function call      || a()&lt;br /&gt;
|-&lt;br /&gt;
| Function reference || AddressOf a&lt;br /&gt;
|-&lt;br /&gt;
| Member b of a      || a.b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment operator v.s. equals operator ===&lt;br /&gt;
&lt;br /&gt;
The {{code | assignment}} operator and the {{code | equals}} operator use the same symbol. It depends on the context which operator is used. The {{code | assignment}} operator is used when a line of code follows the syntax {{code | Identifier {{=}} Value;}}. In all other cases, the {{code | equals}} operator is used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Increment and decrement operators ===&lt;br /&gt;
&lt;br /&gt;
There are two versions of the increment and decrement operators, namely the suffix and the prefix versions. The suffix versions increment or decrements the value hold by the identifier and then returns the old value. The prefix versions increment or decrement the value and return the result.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
 Var i As Integer = 5;&lt;br /&gt;
 WriteLine(i++); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(i--)  // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
 &lt;br /&gt;
 i = 5;&lt;br /&gt;
 WriteLine(++i); // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(--i); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== References equal ===&lt;br /&gt;
&lt;br /&gt;
The {{code | References equal}} operator returns true if both identifiers hold the same reference (or: point to the same object).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  Var i As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  Var j As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  WriteLine(i Is j); // false&lt;br /&gt;
 &lt;br /&gt;
  i = j;&lt;br /&gt;
  WriteLine(i Is j); // true&lt;br /&gt;
&lt;br /&gt;
For types defined as Struct in the Object Explorer, this operator will never return true. When assigning one struct variable to another, the value is copied instead of the reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== AddressOf ===&lt;br /&gt;
&lt;br /&gt;
The {{code | AddressOf}} operator actually returns a CDelegate instance.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 Var Delegate As CDelegate = AddressOf MyFunction;&lt;br /&gt;
 &lt;br /&gt;
 Function MyFunction() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello universe!&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Delegate.Invoke();  // Writes &amp;quot;Hello universe!&amp;quot;;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	<entry>
		<id>http://wiki.en.stne.net/index.php/Scripting:Operators</id>
		<title>Scripting:Operators</title>
		<link rel="alternate" type="text/html" href="http://wiki.en.stne.net/index.php/Scripting:Operators"/>
				<updated>2010-09-10T16:38:16Z</updated>
		
		<summary type="html">&lt;p&gt;Glest Durnham: /* Increment and decrement operators */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Table ==&lt;br /&gt;
In this section, a and b represent either literal values, object references or expressions evaluating to the appropriate type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== String operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Concatenation || a &amp;amp; b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Comparison operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Equals                   || a = b&lt;br /&gt;
|-&lt;br /&gt;
| References equal         || a Is b&lt;br /&gt;
|-&lt;br /&gt;
| Not equal to             || a &amp;lt;&amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than             || a &amp;gt; b&lt;br /&gt;
|-&lt;br /&gt;
| Less than                || a &amp;lt; b&lt;br /&gt;
|-&lt;br /&gt;
| Greater than or equal to || a &amp;gt;= b&lt;br /&gt;
|-&lt;br /&gt;
| Less than or equal to    || a &amp;lt;= b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Arithmetic operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Assignment    || a = b&lt;br /&gt;
|-&lt;br /&gt;
| Addition       || a + b&lt;br /&gt;
|-&lt;br /&gt;
| Subtraction    || a - b&lt;br /&gt;
|-&lt;br /&gt;
| Multiplication || a * b&lt;br /&gt;
|-&lt;br /&gt;
| Division       || a / b&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || a++&lt;br /&gt;
|-&lt;br /&gt;
| Increment      || ++a&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || a--&lt;br /&gt;
|-&lt;br /&gt;
| Decrement      || --a&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logical operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Logical NOT    || NOT a&lt;br /&gt;
|-&lt;br /&gt;
| Logical AND    || a AND b&lt;br /&gt;
|-&lt;br /&gt;
| Logical OR     || a OR b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other operators ===&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;3&amp;quot;&lt;br /&gt;
! Operator name !! Syntax&lt;br /&gt;
|-&lt;br /&gt;
| Function call      || a()&lt;br /&gt;
|-&lt;br /&gt;
| Function reference || AddressOf a&lt;br /&gt;
|-&lt;br /&gt;
| Member b of a      || a.b&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Assignment operator v.s. equals operator ===&lt;br /&gt;
&lt;br /&gt;
The {{code | assignment}} operator and the {{code | equals}} operator use the same symbol. It depends on the context which operator is used. The {{code | assignment}} operator is used when a line of code follows the syntax {{code | Identifier {{=}} Value;}}. In all other cases, the {{code | equals}} operator is used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Increment and decrement operators ===&lt;br /&gt;
&lt;br /&gt;
There are two versions of the increment and decrement operators, namely the suffix and the prefix versions. The suffix versions increment or decrements the value hold by the identifier and then returns the old value. The prefix versions increment or decrement the value and return the result.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
 Var i As Integer = 5;&lt;br /&gt;
 WriteLine(i++); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(i--)  // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
 &lt;br /&gt;
 i = 5;&lt;br /&gt;
 WriteLine(++i); // Writes 6&lt;br /&gt;
 WriteLine(i);   // Writes 6&lt;br /&gt;
 WriteLine(--i); // Writes 5&lt;br /&gt;
 WriteLine(i);   // Writes 5&lt;br /&gt;
&lt;br /&gt;
=== References equal ===&lt;br /&gt;
&lt;br /&gt;
The {{code | References equal}} operator returns true if both identifiers hold the same reference (or: point to the same object).&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  Var i As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  Var j As String = &amp;quot;a&amp;quot;;&lt;br /&gt;
  WriteLine(i Is j); // false&lt;br /&gt;
 &lt;br /&gt;
  i = j;&lt;br /&gt;
  WriteLine(i Is j); // true&lt;br /&gt;
&lt;br /&gt;
For types defined as Struct in the Object Explorer, this operator will never return true. When assigning one struct variable to another, the value is copied instead of the reference.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== AddressOf ===&lt;br /&gt;
&lt;br /&gt;
The {{code | AddressOf}} operator actually returns a CDelegate instance.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
 Var Delegate As CDelegate = AddressOf MyFunction;&lt;br /&gt;
 &lt;br /&gt;
 Function MyFunction() {&lt;br /&gt;
   WriteLine(&amp;quot;Hello universe!&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Delegate.Invoke();  // Writes &amp;quot;Hello universe!&amp;quot;;&lt;/div&gt;</summary>
		<author><name>Glest Durnham</name></author>	</entry>

	</feed>