Docs: Slightly update the script reference

Mainly nil and some edits.
Günther Brammer 2010-08-27 21:19:58 +02:00
parent d1db702be9
commit f5f1aaaa2d
12 changed files with 425 additions and 371 deletions

View File

@ -159,10 +159,10 @@ def printcontents3(f, _):
ihack[0] = ihack[0] + 1
def sheet(url, name):
f.write("<li><img src='../images/bullet_sheet.gif' alt='' />\n" +
"<a href='" + url[4:] + "'>" + name + "</a></li>\n")
"<emlink href='" + url[4:] + "'>" + name + "</emlink></li>\n")
def sheetE(url, name):
f.write("<li><img src='../images/bullet_sheet.gif' alt='' />\n" +
"<a href='" + url[4:] + "'>" + name + "</a> (erweitert)</li>\n")
"<emlink href='" + url[4:] + "'>" + name + "</emlink> (erweitert)</li>\n")
folder("Funktionen nach Kategorie")
cats = parser.cats.keys()
cats.sort()

View File

@ -562,7 +562,7 @@
<xsl:template name="color2">
<xsl:param name="s" select="." />
<!-- the list of keywords -->
<xsl:param name="t" select="'#include|#strict|#appendto|public|private|protected|global|static|var|local|const|int|id|object|string|bool|return|goto|if|else|break|continue|while|for|func|true|false|'" />
<xsl:param name="t" select="'#include|#appendto|public|private|protected|global|static|var|local|const|int|proplist|object|array|string|bool|return|if|else|break|continue|while|for|func|true|false|nil|'" />
<xsl:param name="w" select="substring-before($t, '|')" />
<!-- text before the keyword -->
<xsl:variable name="l" select="substring-before($s, $w)" />
@ -577,7 +577,7 @@
<xsl:value-of select="$s" />
</xsl:when>
<!-- only highlight when the text was found and is not surrounded by other text -->
<xsl:when test="($l or $r) and (not(contains('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $cb)) or $cb='') and (not(contains('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $ca)) or $ca='')">
<xsl:when test="(contains($s, $w)) and (not(contains('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $cb)) or $cb='') and (not(contains('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', $ca)) or $ca='')">
<!-- look for the next keyword in the preceding text -->
<xsl:call-template name="color2">
<xsl:with-param name="s" select="$l" />

File diff suppressed because it is too large Load Diff

View File

@ -60,69 +60,69 @@
Developer mode
<ul id='brn1'>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="index.html">Introduction</a></li>
<emlink href="index.html">Introduction</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="console.html">Engine</a></li>
<emlink href="console.html">Engine</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="cmdline.html">Command Line Parameters</a></li>
<emlink href="cmdline.html">Command Line Parameters</emlink></li>
</ul>
</li>
<li>
<img id='tgl2' class='collapseimg' src='../images/bullet_folder_open.gif' alt='-' onclick='tb(2)' ondblclick='ta(2)' />
<a href="files.html">Game content</a>
<emlink href="files.html">Game content</emlink>
<ul id='brn2'>
<li>
<img id='tgl3' class='collapseimg' src='../images/bullet_folder.gif' alt='-' onclick='tb(3)' ondblclick='ta(3)' />
<a href="definition/index.html">Object Definitions</a>
<emlink href="definition/index.html">Object Definitions</emlink>
<ul id='brn3' class='invisi'>
<li>
<img id='tgl4' class='collapseimg' src='../images/bullet_folder.gif' alt='-' onclick='tb(4)' ondblclick='ta(4)' />
<a href="definition/defcore.html">DefCore</a>
<emlink href="definition/defcore.html">DefCore</emlink>
<ul id='brn4' class='invisi'>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="definition/category.html">Category</a></li>
<emlink href="definition/category.html">Category</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="definition/ocf.html">OCF</a></li>
<emlink href="definition/ocf.html">OCF</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="definition/vertices.html">Vertices</a></li>
<emlink href="definition/vertices.html">Vertices</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="definition/lineconnect.html">LineConnect</a></li>
<emlink href="definition/lineconnect.html">LineConnect</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="definition/cnat.html">CNAT - Contact Attachment</a></li>
<emlink href="definition/cnat.html">CNAT - Contact Attachment</emlink></li>
</ul>
</li>
<li>
<img id='tgl5' class='collapseimg' src='../images/bullet_folder.gif' alt='-' onclick='tb(5)' ondblclick='ta(5)' />
<a href="definition/actmap.html">ActMap</a>
<emlink href="definition/actmap.html">ActMap</emlink>
<ul id='brn5' class='invisi'>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="definition/procedures.html">Procedures</a></li>
<emlink href="definition/procedures.html">Procedures</emlink></li>
</ul>
</li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="definition/script.html">Scripts</a></li>
<emlink href="definition/script.html">Scripts</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="particle/index.html">Particles</a></li>
<emlink href="particle/index.html">Particles</emlink></li>
</ul>
</li>
<li>
<img id='tgl6' class='collapseimg' src='../images/bullet_folder.gif' alt='-' onclick='tb(6)' ondblclick='ta(6)' />
<a href="scenario/index.html">Scenarios</a>
<emlink href="scenario/index.html">Scenarios</emlink>
<ul id='brn6' class='invisi'>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="scenario/scenario.html">Scenario</a></li>
<emlink href="scenario/scenario.html">Scenario</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="scenario/MapCreatorS2.html">Map Generator</a></li>
<emlink href="scenario/MapCreatorS2.html">Map Generator</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="scenario/script.html">Scripts</a></li>
<emlink href="scenario/script.html">Scripts</emlink></li>
</ul>
</li>
<li>
<img id='tgl7' class='collapseimg' src='../images/bullet_folder.gif' alt='-' onclick='tb(7)' ondblclick='ta(7)' />
<a href="material/index.html">Materials</a>
<emlink href="material/index.html">Materials</emlink>
<ul id='brn7' class='invisi'>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="material/c4m.html">Definitions</a></li>
<emlink href="material/c4m.html">Definitions</emlink></li>
</ul>
</li>
<li>
@ -130,37 +130,37 @@
Internationalization
<ul id='brn8' class='invisi'>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="lang.html">Internationalization</a></li>
<emlink href="lang.html">Internationalization</emlink></li>
</ul>
</li>
</ul>
</li>
<li>
<img id='tgl9' class='collapseimg' src='../images/bullet_folder_open.gif' alt='-' onclick='tb(9)' ondblclick='ta(9)' />
<a href="script/index.html">Script</a>
<emlink href="script/index.html">Script</emlink>
<ul id='brn9'>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/Funcs.html">Functions</a></li>
<emlink href="script/Funcs.html">Functions</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/FuncCall.html">Function Call</a></li>
<emlink href="script/FuncCall.html">Function Call</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/Strict.html">#strict</a></li>
<emlink href="script/Typechecks.html">Data Types</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/AppendTo.html">#appendto</a></li>
<emlink href="script/NamedVar.html">Variables</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/BreakContinue.html">break / continue</a></li>
<emlink href="script/operatoren.html">Operators</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/for.html">for</a></li>
<emlink href="script/for.html">for</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/NamedVar.html">Named Variables</a></li>
<emlink href="script/BreakContinue.html">Loop Control</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/operatoren.html">Operators</a></li>
<emlink href="script/AppendTo.html">#appendto</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/Typechecks.html">Data Types</a></li>
<emlink href="script/Effects.html">Effects</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/Effects.html">Effects</a></li>
<emlink href="script/GetXXVal.html">Querying Game Data</emlink></li>
<li><img src='../images/bullet_sheet.gif' alt='-' />
<a href="script/ScriptPlayers.html">Script Players</a></li>
<emlink href="script/ScriptPlayers.html">Script Players</emlink></li>
<!-- Insert Functions here -->
</ul>
</li>

View File

@ -6,7 +6,7 @@
<title>#appendto</title>
<h>#appendto</h>
<part>
<text>By using #appendto you can avoid various object definition overloads.</text>
<text>With #appendto, you can modify an existing object defintion script without changing the original file. For example, a scenario could change flints to cause bigger explosions, without having to duplicate the entire flint in the scenario.</text>
<h id="Syntax">Declaration</h>
<code>#appendto [id]</code>
<text>A script can append itself to one or multiple existing scripts using the <code>#appendto</code> directive. Functions of the same name will overload functions in the target script. The original overloaded functions can still be called using <emlink href="script/fn/inherited.html">inherited</emlink>. #included scripts are not appended with #append, but #appended scripts are included by #include.</text>

View File

@ -3,10 +3,10 @@
SYSTEM '../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../clonk.xsl"?>
<doc>
<title>Break / Continue</title>
<h id="BreakContinue">Break / Continue</h>
<title>break and continue</title>
<h id="BreakContinue">break and continue</h>
<part>
<text>The keywords <code>break</code> and <code>continue</code> are used for manual control of loops:</text>
<text>The keywords <code>break</code> and <code>continue</code> are used for finer control of loops:</text>
<text>
<ul>
<li><code>break</code> ends the enclosing loop. Execution is continued after the end of the loop.</li>

View File

@ -35,22 +35,16 @@ func Aufruf()
<text>Script Object B:</text>
<code>func Activate()
{
var obj = <funclink>FindObject</funclink>(AAAA, -1, -1, -1, -1);
var obj = <funclink>FindObject</funclink>(<funclink>Find_Id</funclink>(AAAA), <funclink>Sort_Distance</funclink>());
obj-&gt;Activate();
} </code>
<text>The function Activate() in the script of object B will first search for the closest object of type A (definition ID AAAA) and store a pointer to this object in the variable "obj". Then the function Activate() is called in the script of object A. To do this we first specifiy the variable containing the pointer to the object, followed by an arrow operator, then the function name including the parameter list (no parameters in this case).</text>
<text>The function Activate() in the script of object B will first search for the closest object of type A (definition ID AAAA) and store a reference to this object in the variable "obj". Then the function Activate() is called in the script of object A. To do this we first specifiy the variable containing the pointer to the object, followed by an arrow, then the function name including the parameter list (no parameters in this case).</text>
<text>Calling Activate() in object B will cause the closest object of type A to be blown up. You may consider this a very primitive type of remote control. By the way, this script will cause an error if no object of type A can be found.</text>
<h>Remarks</h>
<text>You don't <i>have</i> to store the object pointer in a variable as done in this example. You could also continue calling the function directly on the search result as in this case:</text>
<code>func Activate()
{
<funclink>FindObject</funclink>(AAAA, -1, -1, -1, -1)-&gt;Activate();
}</code>
<text>To make sure that an object function is called from a given definition script you can also specify the definition's ID just before the function name. In some cases this may be necessary to resolve ambiguities if functions of the same name override each other.</text>
<code>func Activate()
{
var obj = <funclink>FindObject</funclink>(AAAA, -1, -1, -1, -1);
obj-&gt;AAAA::Activate();
<funclink>FindObject</funclink>(<funclink>Find_Id</funclink>(AAAA), <funclink>Sort_Distance</funclink>())-&gt;Activate();
}</code>
</part>
<h>Indirect call of script functions</h>
@ -66,8 +60,7 @@ func Aufruf()
{
<funclink>Call</funclink>(&quot;TestFunktion&quot;);
}</code>
<text>Usually, indirect calls are a bit slower than direct calls, since they cannot be precompiled and the function will have to be searched by name at runtime.</text>
<text>On the other hand, with indirect calls you can "decide" at runtime which function to call as is done in the following example:</text>
<text>With indirect calls you can "decide" at runtime which function to call as is done in the following example:</text>
<code>func TestFunktion()
{
<funclink>Call</funclink>(<funclink>Format</funclink>(&quot;Aufruf%d&quot;, <funclink>Random</funclink>(3)));
@ -82,4 +75,5 @@ func Aufruf2() { <funclink>Log</funclink>(&quot;Die dritte Funktion wurde aufger
</part>
</part>
<author>PeterW</author><date>2003-05</date>
<author>Günther</author><date>2010-08</date>
</doc>

View File

@ -8,14 +8,14 @@
<part>
<text>A script function represents a length of script code which can be called (or executed) from the engine or from other places in script. Basically, all scripting of a scenario or object is organized in functions.</text>
<h>Parameters and Return Values</h>
<text>Up to ten parameters can be passed in a function call. These are values which can then be used inside function execution. On completion, a function can pass a single value (the return value) back to the caller using the <funclink>return</funclink>() command.</text>
<text>Up to ten parameters can be passed in a function call. These are values which can then be used inside function execution. On completion, a function can pass a single value (the return value) back to the caller using the <funclink>return</funclink> statement.</text>
<h>Syntax</h>
<text>A simple function declaration could look like the following:</text>
<code>func MeineFunktion()
{
<funclink>Log</funclink>(&quot;Meine Funktion wurde aufgerufen!&quot;);
}</code>
<text>A function script is delimited by { } brackets. Preceding this script block is the <strong>function declaration</strong>. The declaration starts with "<code>func</code>", followed by the <strong>function name</strong> (here: "MeineFunktion"). In the ( ) brackets following the function name the <strong>function parameters</strong> can be declared (see below).</text>
<text>A function script is delimited by { } brackets. Preceding this script block is the <b>function declaration</b>. The declaration starts with "<code>func</code>", followed by the <b>function name</b> (here: "MeineFunktion"). In the ( ) brackets following the function name the <b>function parameters</b> can be declared (see below).</text>
<text>When calling this function the message "Meine Funktion wurde aufgerufen!" is displayed.</text>
<code>func ZeigeZahl(int zahl)
{
@ -42,15 +42,15 @@
<funclink>CreateContents</funclink>(def, Clonk);
Clonk-&gt;<funclink>Message</funclink>(msg);
}</code>
<text>This functions creates a given number of a given type of objects inside the specified clonk and displays a variable message above his head. The function declaration ensures that only those values will be accepted that can be converted to the declared parameter types (see also <emlink href="script/Typechecks.html">type checking</emlink>).</text>
<text>This functions creates a given number of a given type of objects inside the specified clonk and displays a variable message above his head. The function declaration ensures that only those values will be accepted that can be converted to the declared parameter types (see also <emlink href="script/Typechecks.html">Data Types</emlink>).</text>
<text>Making a call such as <code>TypParameterFunktion(1, Clonk, "Text", 5)</code> would cause a type checking error.</text>
<h id="spezial">Default Parameters</h>
<text>Unlike in other programming languages you can always pass fewer parameters than are declared in a function declaration.</text>
<text>The following calls to above function are perfectly legal:</text>
<code>ZeigeSumme(1, 2);
ZeigeSumme(1, 2, 3, 4, 5, 6);</code>
<text>In the first call, there are fewer parameters passed to the function than specified in the function declaration. The 'missing' parameters will simply contain the value 0.</text>
<text>If you leave out a parameter it will be the same as passing the value 0.</text>
<text>In the first call, there are fewer parameters passed to the function than specified in the function declaration. The 'missing' parameters will simply contain <code>nil</code>.</text>
<text>If you leave out a parameter it will be the same as passing <code>nil</code>.</text>
<text>In the second call, on the other hand, there are <em>more</em> parameters passed than specified. These are simply not used during function execution. However, a function is still able to access these extra parameters even if they weren't declared in the function declaration: to do this, you can use the <funclink>Par</funclink>() function.</text>
<h>Return Values</h>
<part>
@ -66,8 +66,9 @@ ZeigeSumme(1, 2, 3, 4, 5, 6);</code>
<funclink>Log</funclink>(&quot;Die Differenz zwischen %d und %d beträgt %d!&quot;, Zahl1, Zahl2, Differenz(Zahl1, Zahl2));
} </code>
<text>The call "ZeigeDifferenz(5, 2)" will produce the message "Die Differenz zwischen 5 und 2 beträgt 3!".</text>
<text>If the function does not return a value, an implicit <code>return nil;</code> is implied.</text>
</part>
<h id="Aufrufb">Permissions</h>
<!-- <h id="Aufrufb">Permissions</h>
<part>
<text>A function can have one of three levels of "calling permission". This will determine from where the function may be called:</text>
<text>
@ -94,7 +95,7 @@ ZeigeSumme(1, 2, 3, 4, 5, 6);</code>
<text>Calling this function from another object script will cause an error.</text>
<h>Remark</h>
<text>As in some cases it may seem necessary to call a protected function from another object script, there is a workaround through the <funclink>PrivateCall</funclink> and <funclink>ProtectedCall</funclink> functions.</text>
</part>
</part>-->
<h>Global Functions</h>
<part>
<text>A function is declared globally by placing the "<code>global</code>" keyword before the <code>func</code> marker.</text>
@ -109,7 +110,7 @@ ZeigeSumme(1, 2, 3, 4, 5, 6);</code>
}</code>
<text>This script redefines the engine function <funclink>CreateContents</funclink> while adding a new parameter declaration at the end of the parameter list which now allows to create multiple objects. Notice that <funclink>inherited</funclink> within this function refers to the overloaded engine function <funclink>CreateContents</funclink>.</text>
<h>Attention!</h>
<text>A global script function is executed with the context of the calling function. This means in particular that <funclink>this</funclink>() is the calling object (if the global function was called from an object local scope). Because of this, a global function may not use any object local variables or try to call any object local function. The following object script is illegal:</text>
<text>A global script function is executed with the context of the calling function. This means in particular that <funclink>this</funclink> is the calling object (if the global function was called from an object local scope), or <code>nil</code> (if called from a scenario script). Because of this, a global function may not use any object local variables or try to call any object local function. The following object script is illegal:</text>
<code>local number;
func ObjektFunktion()
{
@ -124,7 +125,7 @@ global func GlobaleFunktion()
<text>Both attempts to access the object local elements will fail. This is understandable because the globally declared function may have been called from any script, even from a scenario script or the script of another object. It will thus not know the declared variable or object function. As the calling context can't be safely known, the engine will throw an error.</text>
<text>Notice: to call an object local function from a different context, use the syntax "<code>this()-&gt;function(...)</code>". This will execute the function in the specified object's context and only cause an error if the function really isn't available.</text>
</part>
<h id="referenzen">References</h>
<!-- <h id="referenzen">References</h>
<text>In some cases, you don't want to pass the value of a variable as a parameter, but the "variable itself" so the function that is called can modify the original variable. This is done by passing a "reference" to the variable as parameter.</text>
<text>Let's say we want to write a function returning the position (coordinates) of a player's highest ranking clonk. This cannot be done with a single return value, as we need to return an x and a y coordinate.</text>
<text>By using references as parameters this can be achieved:</text>
@ -142,8 +143,9 @@ func Aufruf()
<funclink>Log</funclink>(&quot;Die Position des HiRanks von Spieler 1 ist: %d/%d&quot;, hiRankX, hiRankY);
}</code>
<text><code>x</code> and <code>y</code> in <code>GetHiRankPosition</code> are <strong>references</strong>, meaning when the called function modifies these values, the original variables (<code>hiRankX</code> and <code>hiRankY</code>) will be modified and the calling code will have the modified values. Notice, however, that you <em>have</em> to specify true variables as parameters for references. You cannot make a call such as "<code>GetHiRankPosition(0, hiRankX + 1, hiRankY)</code>" as in this case "<code>iHiRankX + 1</code>" is not a variable but a numeric result.</text>
<text>Notice that in C4Script "<code>&amp;</code>" is a data type of its own. You may not specify an extra data type with it, such as in "<code>int &amp;x</code>".</text>
<text>Notice that in C4Script "<code>&amp;</code>" is a data type of its own. You may not specify an extra data type with it, such as in "<code>int &amp;x</code>".</text>-->
</part>
<author>PeterW</author><date>2002-07</date>
<author>matthes</author><date>2004-06</date>
<author>Günther</author><date>2010-08</date>
</doc>

View File

@ -3,8 +3,8 @@
SYSTEM '../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../clonk.xsl"?>
<doc>
<title>Named Variables</title>
<h>Named Variables</h>
<title>Variables</title>
<h>Variables</h>
<part>
<text>Variables are placeholders for values stored in a script. A variable stores a value in one of several <emlink href="script/Typechecks.html">data types</emlink>.</text>
<text>There are three different scopes in which a variable can be declared. Variables are not visible outside their declared scope.</text>
@ -35,7 +35,7 @@
<text>Variables are declared using the following syntax:</text>
<code>{ var / local / static } name [= expr] [, name [= expr] ... ];</code>
<text>The variable's scope, followed by the variable's name.</text>
<text>Optionally, you can assign a value to the variable directly at declaration time. However, this is possible for function local (<code>var</code>) variables only. Without initialization variables always start with value 0.</text>
<text>Optionally, you can assign a value to the variable directly at declaration time. However, this is possible for function local (<code>var</code>) variables only. Without initialization variables always start with <code>nil</code>.</text>
<text>Additional variable declarations may follow, separated by comma. The declaration must always be ended with a semicolon.</text>
<h>Example:</h>
<code>static object_count;

View File

@ -19,53 +19,59 @@
<col><code>int</code></col>
<col>Integer</col>
<col>A whole number from -2.147.483.648 to +2.147.483.647.</col>
<col><code>42 </code></col>
<col><code>42</code></col>
</row>
<row>
<col><code>bool</code></col>
<col>Boolean</col>
<col>"true" (value <code>true</code>) or "false" (value <code>false</code>). Expected as parameter by many structures such as <funclink>if</funclink> and <funclink>while</funclink>.</col>
<col><code>true </code></col>
<col><code>true</code></col>
</row>
<row>
<col><code>id</code></col>
<col>definition id</col>
<col>ID of an object definition (see <emlink href="definition/index.html#ObjektundEntwicklerIdentifikation">Object Definitions</emlink>).Will be changed into a proplist immediately.</col>
<col><code>Clonk </code></col>
<col><code>Clonk</code></col>
</row>
<row>
<col><code>string</code></col>
<col>String</col>
<col>Any text.</col>
<col><code>&quot;Dies ist ein Text!&quot; </code></col>
<col><code>&quot;Dies ist ein Text!&quot;</code></col>
</row>
<row>
<col><code>array</code></col>
<col>Array</col>
<col>A type containing multiple variables, whose number can be enquired with <funclink>GetLength</funclink>, and which can be recalled with <code><em>array</em>[<em>index</em>]</code>. Since CR.</col>
<col><code>[0,42,Clonk] </code></col>
<col>A type containing multiple variables, whose number can be enquired with <funclink>GetLength</funclink>, and which can be recalled with <code><em>array</em>[<em>index</em>]</code>.</col>
<col><code>[0,23,Clonk]</code></col>
</row>
<row>
<col><code>proplist</code></col>
<col>Object</col>
<col>A general purpose object type. <funclink>GetProperty</funclink> and <funclink>SetProperty</funclink> can get respectively set properties. If the property <code>"Prototype"</code> is set, and a property that is not set is gotten, the prototype is asked.</col>
<col><code>{ foo = 0, &quot;bar baz&quot; = 42, Prototype = Clonk }</code></col>
<col><code>{ foo = 0, &quot;bar baz&quot; = 13, Prototype = Clonk }</code></col>
</row>
<row>
<col><code>object</code></col>
<col>Ingame object</col>
<col>Ingame Object</col>
<col>Reference to an existing object at runtime. No direct representation. See <funclink>FindObject</funclink>()</col>
<col>CreateObject(Clonk)</col>
<col><code>CreateObject(Clonk)</code></col>
</row>
<row>
<col><code>any</code></col>
<col></col>
<col>The type of <code>nil</code>. When used as a function parameter type, the type check is skipped.</col>
<col><code>nil</code></col>
</row>
</table>
</text>
<text>Additionally, there are two special types:</text>
<!-- <text>Additionally, there are two special types:</text>
<text>
<ul>
<li><code>any</code>: The type is unknown or does not make a difference. "0" always has this type.</li>
<li><code>any</code>: The type is unknown or does not make a difference. <code>nil</code> always has this type.</li>
<li><code>&amp;</code>: The value is a reference, for example to a variable. It behaves exactly as the target value, but can be changed (for example with the operator "<code>=</code>"). See also <emlink href="script/Funcs.html#referenzen">Reference parameters</emlink>.</li>
</ul>
</text>
</text>-->
<h>Arrays</h>
<part>
<text>Arrays can be created directly with <code>[<em>expression 1</em>, <em>expression 2</em>, ...]</code> or indirectly with <funclink>CreateArray</funclink>(). They are automatically enlarged if necessary on element access, but it's faster to create them with the needed length from the start. If an array is stored in a variable or used as a parameter to a function, the new variable has it's own copy of the array. The actual copy is deferred if possible, though. If an array is passed to a function for modification, a reference has to be used.</text>
@ -101,6 +107,10 @@
}</code>
<text>This function calls <code>DoExplode()</code> on the six nearest Dynamite objects.</text>
</part>
<h>Proplists</h>
<part>
<text>Proplists can be created with <code>{<em>key 1</em>=<em>expression 1</em>, <em>key 1</em>=<em>expression 1</em>, ...}</code> or with <funclink>CreateProplist</funclink>.</text>
</part>
<h>Conversion</h>
<text>Consult the following table to determine which types can be converted and which conversions might cause errors:</text>
<text>

View File

@ -6,7 +6,7 @@
<title>The 'for' Loop</title>
<h>The 'for' Loop</h>
<part>
<text>The <code>for</code> loop is a very convenient loop with starting initialization. It is most often used as <a href="#Zaehlschleife">counting loop</a>. It will take three statements as parameters, each separated by a ';' semicolon. Followed by the code block to be executed:</text>
<text>The <code>for</code> loop is a convenient loop with starting initialization. It is most often used as <a href="#Zaehlschleife">counting loop</a>. It will take three statements as parameters, each separated by a ';' semicolon. Followed by the code block to be executed:</text>
<code>for([Initialisierung]; [Bedingung]; [Inkrementierung]))
[Auszuführende Anweisung];
</code>
@ -17,19 +17,21 @@
<li>The third statement is executed after each loop execution. This is a good place to count up or down your counter variables.</li>
</ul>
</text>
<text>It is possible to omit any of the three statements. If there is no condition statement, then the loop will run forever unless it is manually interrupted (i.e. using the <code>break</code> keyword). This is an infinite loop:</text>
<text>It is possible to omit any of the three statements. If there is no condition statement, then the loop will run forever unless it is interrupted from the loop body (i.e. using the <code>break</code> keyword). This is an infinite loop:</text>
<code>for(;;)
<funclink>Log</funclink>(&quot;Fl00d!&quot;);
</code>
<h id="Zaehlschleife">Using for as a counting loop</h>
<text>This is the most common use of the for loop. If, for example, you want to print all numbers from 1 to 10, you would write:</text>
<code>for(var i = 1; i &lt;= 10; i++)
<code>for(var i = 1; i &lt;= 10; ++i)
<funclink>Log</funclink>(&quot;%d&quot;, i);
</code>
<text>Notice: the following <funclink>while</funclink> loop would do exactly the same:</text>
<code>var i = 0;
<funclink>while</funclink>(++i &lt;= 10)
<code>var i = 1;
<funclink>while</funclink>(i &lt;= 10) {
<funclink>Log</funclink>(&quot;%d&quot;, i);
++i;
}
</code>
<h id="Arrayschleife">Using for to iterate over an array</h>
<text>Another function of the <code>for</code>-loop is iterating over arrays. Each element of the array is stored in the variable and the loop body executed for that element. The script looks like this:</text>
@ -44,4 +46,5 @@
<text>Counts backwards from 10 to 1.</text>
</part>
<author>Peter</author><date>2004-06</date>
<author>Günther</author><date>2010-08</date>
</doc>

View File

@ -24,9 +24,9 @@
</code>
<text>Directly following the function name you can include a short descriptive text, an icon reference (object ID of the object whose image is to be used), and a conditional statement for when to display the function in the context menu, all within a set of [ ] brackets, separated by a | symbol.</text>
<h id="VariablenParameter">Variables/Parameters</h>
<text>Variables can hold values of type int, bool, id, string, or object. Any parameter not directly specified in a function call will hold the default value 0. Functions can have a maximum of ten parameters.</text>
<text>Variables can hold values of type <code>int</code>, <code>bool</code>, <code>string</code>, <code>proplist</code>, <code>array</code> or <code>object</code>. Any parameter not directly specified in a function call will hold the default value <code>nil</code>. Functions can have a maximum of ten parameters.</text>
<h id="Kommentare">Comments</h>
<text>Scripts may contain code comments in C-style. Comment test will be completely ignored when the script is comipiled for execution.</text>
<text>Scripts may contain code comments in C-style. Comment text will be completely ignored when the script is compiled for execution.</text>
<code>func MeineFunktion() // Ein Kommentar bis zum Ende der Zeile
{
<funclink>Message</funclink>(&quot;Dieser Code wird ausgeführt&quot;); /* Ein Kommentar in einem Block */ <funclink>Message</funclink>(&quot;Dieser auch&quot;);
@ -34,14 +34,16 @@
}
</code>
<h id="Infos">Additional Information</h>
<text><emlink href="script/AppendTo.html">#appendto: for appending code to existing scripts</emlink></text>
<text><emlink href="script/BreakContinue.html">Loop Control</emlink></text>
<text><emlink href="script/Funcs.html">Functions</emlink></text>
<text><emlink href="script/FuncCall.html">Calling Script Functions</emlink></text>
<text><emlink href="script/Typechecks.html">Data Types</emlink></text>
<text><emlink href="script/NamedVar.html">Variables and their Scope</emlink></text>
<text><emlink href="script/operatoren.html">Operators: +, -, = etc. in C4Script</emlink></text>
<text><emlink href="script/for.html">for Loop</emlink></text>
<text><emlink href="script/BreakContinue.html">Loop Control</emlink></text>
<text><emlink href="script/AppendTo.html">#appendto: for appending code to existing scripts</emlink></text>
<text><emlink href="script/Effects.html">Effects</emlink></text>
<text><emlink href="script/GetXXVal.html">Querying Game Data</emlink></text>
<text><emlink href="script/NamedVar.html">Named variables and their scope</emlink></text>
<text><emlink href="script/operatoren.html">Operators: +, -, = etc. in C4Script</emlink></text>
<text><emlink href="script/Typechecks.html">Data type checking at runtime</emlink></text>
<text><emlink href="script/ScriptPlayers.html">Script Player (i.e. AI player)</emlink></text>
</part>
<author>Sven2</author><date>2002-04</date>