


<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://bitfighter.org/wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://bitfighter.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Script_structure</id>
		<title>Script structure - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://bitfighter.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Script_structure"/>
		<link rel="alternate" type="text/html" href="http://bitfighter.org/wiki/index.php?title=Script_structure&amp;action=history"/>
		<updated>2026-12-03T17:39:43Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.15</generator>

	<entry>
		<id>http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4921&amp;oldid=prev</id>
		<title>Kaen at 17:22, 27 February 2013</title>
		<link rel="alternate" type="text/html" href="http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4921&amp;oldid=prev"/>
				<updated>2013-02-27T17:22:13Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 17:22, 27 February 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Event handlers (Event Phase)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Event handlers (Event Phase)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Note that as of 015a, levelgen scripts do not have an Event Phase, and are terminated after the Initialization Phase.&amp;#160; This will change with a future release.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;During the &amp;quot;Load Phase&amp;quot; the script is essentially &amp;quot;executed&amp;quot; in order to get all the functions loaded into the global namespace where they can be called by Bitfighter. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Only &lt;/ins&gt;code that is not contained in a function is run, and while you can possibly do some useful things during this phase (especially with a levelgen), it is really best to restrict any &amp;quot;loose code&amp;quot; (i.e. not contained in a function) to defining global variables. Any variables defined in this phase are considered global unless the local keyword is used. Command line args passed to the script are &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;'''not''' &lt;/ins&gt;available during this phase.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;During the &amp;quot;Load Phase&amp;quot; the script is essentially &amp;quot;executed&amp;quot; in order to get all the functions loaded into the global namespace where they can be called by Bitfighter. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt; Any &lt;/del&gt;code that is not contained in a function is run, and while you can possibly do some useful things during this phase (especially with a levelgen), it is really best to restrict any &amp;quot;loose code&amp;quot; (i.e. not contained in a function) to defining global variables. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt; &lt;/del&gt;Any variables defined in this phase are considered global unless the local keyword is used. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt; &lt;/del&gt;Command line args passed to the script are &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;NOT &lt;/del&gt;available during this phase.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Immediately following the Load Phase is the Initialization Phase.&amp;#160; Initialization essentially consists of running a function called main().&amp;#160; All scripts are required to have a main() function, but it can be empty.&amp;#160; This is a good time to set variables and create any structures that might be needed by the script.&amp;#160; Any variables created in main() are considered global unless declared with the local keyword, but your scripts will be clearer if they are declared during the Load Phase.&amp;#160; Command line args passed to the script are available, and are stored in the arg table (which is the Lua standard).&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Immediately following the Load Phase is the Initialization Phase.&amp;#160; Initialization essentially consists of running a function called main().&amp;#160; All scripts are required to have a main() function, but it can be empty.&amp;#160; This is a good time to set variables and create any structures that might be needed by the script.&amp;#160; Any variables created in main() are considered global unless declared with the local keyword, but your scripts will be clearer if they are declared during the Load Phase.&amp;#160; Command line args passed to the script are available, and are stored in the arg table (which is the Lua standard).&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As the game proceeds, events may occur that trigger calls to the script.&amp;#160; Generally, scripts need to register to receive a particular event (see [[Programming_robots#Currently_defined_events|the list of events]]).&amp;#160; When an event occurs in the game, the corresponding function is called in the script, where it can take action accordingly.&amp;#160; Each game frame, a Tick event is fired, and if a script has a function called onTick(), it will be executed.&amp;#160; Scripts do not need to register to receive Tick events.&amp;#160; Note that to reduce errors, all variables used in the event handling code must be explicitly declared, either during the Load or Initialization&amp;#160; phases, or using the local or global keywords.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As the game proceeds, events may occur that trigger calls to the script.&amp;#160; Generally, scripts need to register to receive a particular event (see [[Programming_robots#Currently_defined_events|the list of events]]).&amp;#160; When an event occurs in the game, the corresponding function is called in the script, where it can take action accordingly.&amp;#160; Each game frame, a Tick event is fired, and if a script has a function called onTick(), it will be executed.&amp;#160; Scripts do not need to register to receive Tick events.&amp;#160; Note that to reduce errors, all variables used in the event handling code must be explicitly declared, either during the Load or Initialization&amp;#160; phases, or using the local or global keywords.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kaen</name></author>	</entry>

	<entry>
		<id>http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4153&amp;oldid=prev</id>
		<title>Watusimoto at 12:01, 15 December 2011</title>
		<link rel="alternate" type="text/html" href="http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4153&amp;oldid=prev"/>
				<updated>2011-12-15T12:01:33Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 12:01, 15 December 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Event handlers (Event Phase)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Event handlers (Event Phase)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that as of &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;05a&lt;/del&gt;, levelgen scripts do not have an Event Phase, and are terminated after the Initialization Phase.&amp;#160; This will change with a future release.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that as of &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;015a&lt;/ins&gt;, levelgen scripts do not have an Event Phase, and are terminated after the Initialization Phase.&amp;#160; This will change with a future release.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;During the &amp;quot;Load Phase&amp;quot; the script is essentially &amp;quot;executed&amp;quot; in order to get all the functions loaded into the global namespace where they can be called by Bitfighter.&amp;#160; Any code that is not contained in a function is run, and while you can possibly do some useful things during this phase (especially with a levelgen), it is really best to restrict any &amp;quot;loose code&amp;quot; (i.e. not contained in a function) to defining global variables.&amp;#160; Any variables defined in this phase are considered global unless the local keyword is used.&amp;#160; Command line args passed to the script are NOT available during this phase.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;During the &amp;quot;Load Phase&amp;quot; the script is essentially &amp;quot;executed&amp;quot; in order to get all the functions loaded into the global namespace where they can be called by Bitfighter.&amp;#160; Any code that is not contained in a function is run, and while you can possibly do some useful things during this phase (especially with a levelgen), it is really best to restrict any &amp;quot;loose code&amp;quot; (i.e. not contained in a function) to defining global variables.&amp;#160; Any variables defined in this phase are considered global unless the local keyword is used.&amp;#160; Command line args passed to the script are NOT available during this phase.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Watusimoto</name></author>	</entry>

	<entry>
		<id>http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4144&amp;oldid=prev</id>
		<title>Watusimoto: Script Structure moved to Script structure: Follow conventions of capitialization</title>
		<link rel="alternate" type="text/html" href="http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4144&amp;oldid=prev"/>
				<updated>2011-12-15T09:10:20Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;a href=&quot;/wiki/index.php/Script_Structure&quot; class=&quot;mw-redirect&quot; title=&quot;Script Structure&quot;&gt;Script Structure&lt;/a&gt; moved to &lt;a href=&quot;/wiki/index.php/Script_structure&quot; title=&quot;Script structure&quot;&gt;Script structure&lt;/a&gt;: Follow conventions of capitialization&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 09:10, 15 December 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Watusimoto</name></author>	</entry>

	<entry>
		<id>http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4143&amp;oldid=prev</id>
		<title>Watusimoto at 09:05, 15 December 2011</title>
		<link rel="alternate" type="text/html" href="http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4143&amp;oldid=prev"/>
				<updated>2011-12-15T09:05:31Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 09:05, 15 December 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Immediately following the Load Phase is the Initialization Phase.&amp;#160; Initialization essentially consists of running a function called main().&amp;#160; All scripts are required to have a main() function, but it can be empty.&amp;#160; This is a good time to set variables and create any structures that might be needed by the script.&amp;#160; Any variables created in main() are considered global unless declared with the local keyword, but your scripts will be clearer if they are declared during the Load Phase.&amp;#160; Command line args passed to the script are available, and are stored in the arg table (which is the Lua standard).&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Immediately following the Load Phase is the Initialization Phase.&amp;#160; Initialization essentially consists of running a function called main().&amp;#160; All scripts are required to have a main() function, but it can be empty.&amp;#160; This is a good time to set variables and create any structures that might be needed by the script.&amp;#160; Any variables created in main() are considered global unless declared with the local keyword, but your scripts will be clearer if they are declared during the Load Phase.&amp;#160; Command line args passed to the script are available, and are stored in the arg table (which is the Lua standard).&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As the game proceeds, events may occur that trigger calls to the script.&amp;#160; Generally, scripts need to register to receive a particular event (see [[Programming_robots#Currently_defined_events|the list of events]]).&amp;#160; When an event occurs in the game, the corresponding function is called in the script, where it can take action accordingly.&amp;#160; Each game frame, a Tick event is fired, and if a script has a function called onTick(), it will be executed.&amp;#160; Scripts do not need to register to receive Tick events.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As the game proceeds, events may occur that trigger calls to the script.&amp;#160; Generally, scripts need to register to receive a particular event (see [[Programming_robots#Currently_defined_events|the list of events]]).&amp;#160; When an event occurs in the game, the corresponding function is called in the script, where it can take action accordingly.&amp;#160; Each game frame, a Tick event is fired, and if a script has a function called onTick(), it will be executed.&amp;#160; Scripts do not need to register to receive Tick events&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;.&amp;#160; Note that to reduce errors, all variables used in the event handling code must be explicitly declared, either during the Load or Initialization&amp;#160; phases, or using the local or global keywords&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Watusimoto</name></author>	</entry>

	<entry>
		<id>http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4142&amp;oldid=prev</id>
		<title>Watusimoto at 09:03, 15 December 2011</title>
		<link rel="alternate" type="text/html" href="http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4142&amp;oldid=prev"/>
				<updated>2011-12-15T09:03:47Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 09:03, 15 December 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Immediately following the Load Phase is the Initialization Phase.&amp;#160; Initialization essentially consists of running a function called main().&amp;#160; All scripts are required to have a main() function, but it can be empty.&amp;#160; This is a good time to set variables and create any structures that might be needed by the script.&amp;#160; Any variables created in main() are considered global unless declared with the local keyword, but your scripts will be clearer if they are declared during the Load Phase.&amp;#160; Command line args passed to the script are available, and are stored in the arg table (which is the Lua standard).&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Immediately following the Load Phase is the Initialization Phase.&amp;#160; Initialization essentially consists of running a function called main().&amp;#160; All scripts are required to have a main() function, but it can be empty.&amp;#160; This is a good time to set variables and create any structures that might be needed by the script.&amp;#160; Any variables created in main() are considered global unless declared with the local keyword, but your scripts will be clearer if they are declared during the Load Phase.&amp;#160; Command line args passed to the script are available, and are stored in the arg table (which is the Lua standard).&amp;#160; &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As the game proceeds, events may occur that trigger calls to the script.&amp;#160; Generally, scripts need to register to receive a particular event (see [[Programming_robots#Currently_defined_events|the list of events]]&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;)&lt;/del&gt;).&amp;#160; When an event occurs in the game, the corresponding function is called in the script, where it can take action accordingly.&amp;#160; Each game frame, a Tick event is fired, and if a script has a function called onTick(), it will be executed.&amp;#160; Scripts do not need to register to receive Tick events.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As the game proceeds, events may occur that trigger calls to the script.&amp;#160; Generally, scripts need to register to receive a particular event (see [[Programming_robots#Currently_defined_events|the list of events]]).&amp;#160; When an event occurs in the game, the corresponding function is called in the script, where it can take action accordingly.&amp;#160; Each game frame, a Tick event is fired, and if a script has a function called onTick(), it will be executed.&amp;#160; Scripts do not need to register to receive Tick events.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Watusimoto</name></author>	</entry>

	<entry>
		<id>http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4141&amp;oldid=prev</id>
		<title>Watusimoto: Created page</title>
		<link rel="alternate" type="text/html" href="http://bitfighter.org/wiki/index.php?title=Script_structure&amp;diff=4141&amp;oldid=prev"/>
				<updated>2011-12-15T09:03:19Z</updated>
		
		<summary type="html">&lt;p&gt;Created page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Programming levelgens|Levelgen]] and [[Programming robots|Robot]] scripts share the same general program structure. They generally contain three sections, and are executed during the corresponding phases:&lt;br /&gt;
# Global variable declarations  (Load Phase)&lt;br /&gt;
# Initialization code (Initialization Phase)&lt;br /&gt;
# Event handlers (Event Phase)&lt;br /&gt;
&lt;br /&gt;
Note that as of 05a, levelgen scripts do not have an Event Phase, and are terminated after the Initialization Phase.  This will change with a future release.&lt;br /&gt;
&lt;br /&gt;
During the &amp;quot;Load Phase&amp;quot; the script is essentially &amp;quot;executed&amp;quot; in order to get all the functions loaded into the global namespace where they can be called by Bitfighter.  Any code that is not contained in a function is run, and while you can possibly do some useful things during this phase (especially with a levelgen), it is really best to restrict any &amp;quot;loose code&amp;quot; (i.e. not contained in a function) to defining global variables.  Any variables defined in this phase are considered global unless the local keyword is used.  Command line args passed to the script are NOT available during this phase.&lt;br /&gt;
&lt;br /&gt;
Immediately following the Load Phase is the Initialization Phase.  Initialization essentially consists of running a function called main().  All scripts are required to have a main() function, but it can be empty.  This is a good time to set variables and create any structures that might be needed by the script.  Any variables created in main() are considered global unless declared with the local keyword, but your scripts will be clearer if they are declared during the Load Phase.  Command line args passed to the script are available, and are stored in the arg table (which is the Lua standard).  &lt;br /&gt;
&lt;br /&gt;
As the game proceeds, events may occur that trigger calls to the script.  Generally, scripts need to register to receive a particular event (see [[Programming_robots#Currently_defined_events|the list of events]])).  When an event occurs in the game, the corresponding function is called in the script, where it can take action accordingly.  Each game frame, a Tick event is fired, and if a script has a function called onTick(), it will be executed.  Scripts do not need to register to receive Tick events.&lt;/div&gt;</summary>
		<author><name>Watusimoto</name></author>	</entry>

	</feed>