<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://chronocrash.com/openbor/wiki/index.php?action=history&amp;feed=atom&amp;title=Level_Scripts</id>
	<title>Level Scripts - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://chronocrash.com/openbor/wiki/index.php?action=history&amp;feed=atom&amp;title=Level_Scripts"/>
	<link rel="alternate" type="text/html" href="https://chronocrash.com/openbor/wiki/index.php?title=Level_Scripts&amp;action=history"/>
	<updated>2026-11-14T05:08:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://chronocrash.com/openbor/wiki/index.php?title=Level_Scripts&amp;diff=1001&amp;oldid=prev</id>
		<title>Dcurrent at 19:56, 20 August 2026</title>
		<link rel="alternate" type="text/html" href="https://chronocrash.com/openbor/wiki/index.php?title=Level_Scripts&amp;diff=1001&amp;oldid=prev"/>
		<updated>2026-08-20T19:56:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 14:56, 20 August 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l176&quot;&gt;Line 176:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 176:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[Onspawnscript]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[Onspawnscript]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[Script Overview]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [[Script Overview]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; 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;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Openbor]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Dcurrent</name></author>
	</entry>
	<entry>
		<id>https://chronocrash.com/openbor/wiki/index.php?title=Level_Scripts&amp;diff=1000&amp;oldid=prev</id>
		<title>Dcurrent: Created page with &quot;Category:Level Category:Script  &#039;&#039;&#039;levelscript&#039;&#039;&#039; is a level-start event hook. OpenBOR provides two forms: the automatic project-wide &lt;code&gt;data/scripts/level.c&lt;/code&gt; script and a &lt;code&gt;levelscript&lt;/code&gt; declared by an individual level. Both execute once after the level is loaded and active players are spawned, but before normal level updates begin.  This timing makes level scripts ideal for establishing the initial state of a stage. Common uses include resetti...&quot;</title>
		<link rel="alternate" type="text/html" href="https://chronocrash.com/openbor/wiki/index.php?title=Level_Scripts&amp;diff=1000&amp;oldid=prev"/>
		<updated>2026-08-20T19:55:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/openbor/wiki/index.php/Category:Level&quot; title=&quot;Category:Level&quot;&gt;Category:Level&lt;/a&gt; &lt;a href=&quot;/openbor/wiki/index.php/Category:Script&quot; title=&quot;Category:Script&quot;&gt;Category:Script&lt;/a&gt;  &amp;#039;&amp;#039;&amp;#039;levelscript&amp;#039;&amp;#039;&amp;#039; is a level-start event hook. OpenBOR provides two forms: the automatic project-wide &amp;lt;code&amp;gt;data/scripts/level.c&amp;lt;/code&amp;gt; script and a &amp;lt;code&amp;gt;levelscript&amp;lt;/code&amp;gt; declared by an individual level. Both execute once after the level is loaded and active players are spawned, but before normal level updates begin.  This timing makes level scripts ideal for establishing the initial state of a stage. Common uses include resetti...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Level]]&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;levelscript&amp;#039;&amp;#039;&amp;#039; is a level-start event hook. OpenBOR provides two forms: the automatic project-wide &amp;lt;code&amp;gt;data/scripts/level.c&amp;lt;/code&amp;gt; script and a &amp;lt;code&amp;gt;levelscript&amp;lt;/code&amp;gt; declared by an individual level. Both execute once after the level is loaded and active players are spawned, but before normal level updates begin.&lt;br /&gt;
&lt;br /&gt;
This timing makes level scripts ideal for establishing the initial state of a stage. Common uses include resetting counters, preparing objectives, configuring shared systems, setting level-specific rules, initializing player state, and spawning controller entities.&lt;br /&gt;
&lt;br /&gt;
== Forms ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Form&lt;br /&gt;
! Scope&lt;br /&gt;
! Setup&lt;br /&gt;
! Execution order&lt;br /&gt;
|-&lt;br /&gt;
| Global level script&lt;br /&gt;
| Every level in the project&lt;br /&gt;
| Create &amp;lt;code&amp;gt;data/scripts/level.c&amp;lt;/code&amp;gt;&lt;br /&gt;
| First&lt;br /&gt;
|-&lt;br /&gt;
| Level-specific script&lt;br /&gt;
| Level containing the command&lt;br /&gt;
| Add &amp;lt;code&amp;gt;levelscript&amp;lt;/code&amp;gt; to the level definition&lt;br /&gt;
| Second&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Both forms use a &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; entry point and receive no automatic event variables.&lt;br /&gt;
&lt;br /&gt;
== Global Level Script ==&lt;br /&gt;
&lt;br /&gt;
OpenBOR automatically loads &amp;lt;code&amp;gt;data/scripts/level.c&amp;lt;/code&amp;gt; when the file is present. No command is required in a level definition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    // Perform project-wide level initialization here.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The global script executes at the start of every level. Use it for initialization that should be consistent throughout the project, such as clearing stage statistics, preparing common HUD logic, resetting shared objectives, or activating a universal level controller.&lt;br /&gt;
&lt;br /&gt;
== Level-Specific Script ==&lt;br /&gt;
&lt;br /&gt;
Add &amp;lt;code&amp;gt;levelscript&amp;lt;/code&amp;gt; to a level definition and provide the path to the script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
levelscript data/scripts/levels/storm_docks_start.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The referenced script uses the same entry point as the global form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    // Perform initialization for this level here.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The level-specific script executes only when OpenBOR starts the level containing the command. It is well suited to objectives, environmental rules, encounter controllers, scripted introductions, alternate HUD modes, or other setup unique to that level.&lt;br /&gt;
&lt;br /&gt;
Only one &amp;lt;code&amp;gt;levelscript&amp;lt;/code&amp;gt; command is available to a level. Multiple initialization tasks may be organized into functions and called from the script&amp;#039;s &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; when needed.&lt;br /&gt;
&lt;br /&gt;
== Execution ==&lt;br /&gt;
&lt;br /&gt;
The relevant level-start sequence is:&lt;br /&gt;
&lt;br /&gt;
# OpenBOR loads and configures the level.&lt;br /&gt;
# OpenBOR resets the new level&amp;#039;s immediate runtime state.&lt;br /&gt;
# Active players with remaining lives are spawned.&lt;br /&gt;
# &amp;lt;code&amp;gt;data/scripts/level.c&amp;lt;/code&amp;gt; executes when present.&lt;br /&gt;
# The level-specific &amp;lt;code&amp;gt;levelscript&amp;lt;/code&amp;gt; executes when declared.&lt;br /&gt;
# OpenBOR enters the normal update loop.&lt;br /&gt;
&lt;br /&gt;
Level data and active player entities are therefore available to both scripts. Ordinary level progression and the first normal update cycle have not yet begun.&lt;br /&gt;
&lt;br /&gt;
The level-specific script executes after the global script, so it can build on or override state established by &amp;lt;code&amp;gt;level.c&amp;lt;/code&amp;gt;. This ordering supports a useful division of responsibility: define project defaults globally, then specialize them for the current level.&lt;br /&gt;
&lt;br /&gt;
Level scripts are start events, not recurring updates. Logic that must run continuously belongs in an update script, an entity script, or another appropriate event hook.&lt;br /&gt;
&lt;br /&gt;
== Example: Shared and Level-Specific Setup ==&lt;br /&gt;
&lt;br /&gt;
The following &amp;lt;code&amp;gt;data/scripts/level.c&amp;lt;/code&amp;gt; resets several values used throughout a project whenever a level begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    setglobalvar(&amp;quot;stage_hit_count&amp;quot;, 0);&lt;br /&gt;
    setglobalvar(&amp;quot;stage_damage_total&amp;quot;, 0);&lt;br /&gt;
    setglobalvar(&amp;quot;stage_objective_complete&amp;quot;, 0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An individual level can then define its own objective and environmental profile:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
levelscript data/scripts/levels/storm_docks_start.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    setglobalvar(&amp;quot;stage_objective&amp;quot;, &amp;quot;protect_convoy&amp;quot;);&lt;br /&gt;
    setglobalvar(&amp;quot;stage_weather&amp;quot;, &amp;quot;storm&amp;quot;);&lt;br /&gt;
    setglobalvar(&amp;quot;stage_reinforcement_limit&amp;quot;, 3);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Recurring scripts, HUD logic, spawn scripts, and model scripts may read these values later. The example is intentionally compact - the same arrangement can initialize far more elaborate objective managers, branching encounters, weather controllers, scoring rules, or cinematic systems.&lt;br /&gt;
&lt;br /&gt;
== Example: Preparing Active Players ==&lt;br /&gt;
&lt;br /&gt;
Active player entities already exist when the event runs. This allows a global level script to mark or configure them before the first ordinary update:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    int player;&lt;br /&gt;
    int player_count = openborvariant(&amp;quot;maxplayers&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    for (player = 0; player &amp;lt; player_count; player++)&lt;br /&gt;
    {&lt;br /&gt;
        void entity = getplayerproperty(player, &amp;quot;entity&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        if (entity)&lt;br /&gt;
        {&lt;br /&gt;
            setentityvar(entity, &amp;quot;stage_ready&amp;quot;, 1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other systems can consume &amp;lt;code&amp;gt;stage_ready&amp;lt;/code&amp;gt; to begin entrance behavior, apply level-specific equipment, initialize challenge conditions, or coordinate multiplayer presentation. Keeping the start hook focused on setup allows the ongoing behavior to remain in the scripts designed to update it.&lt;br /&gt;
&lt;br /&gt;
== Other Uses ==&lt;br /&gt;
&lt;br /&gt;
Quick applications include:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Objective setup&amp;#039;&amp;#039;&amp;#039; - Establish targets, timers, counters, failure conditions, escort data, or challenge rules.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;System reset&amp;#039;&amp;#039;&amp;#039; - Clear per-stage statistics, temporary resources, encounter flags, or branching state.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Player preparation&amp;#039;&amp;#039;&amp;#039; - Apply stage-specific status, equipment, positioning rules, interface modes, or cooperative roles.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Environment control&amp;#039;&amp;#039;&amp;#039; - Initialize weather, lighting, palette, camera, audio, or hazard controllers.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Encounter management&amp;#039;&amp;#039;&amp;#039; - Spawn or configure invisible controller entities that coordinate complex sequences.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Presentation&amp;#039;&amp;#039;&amp;#039; - Prepare introductions, title cards, dialogue systems, custom HUD elements, or cinematic logic.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Project defaults&amp;#039;&amp;#039;&amp;#039; - Use &amp;lt;code&amp;gt;level.c&amp;lt;/code&amp;gt; to establish a common baseline, then let individual levels replace only the values they need.&lt;br /&gt;
&lt;br /&gt;
== Related Scripts ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Script&lt;br /&gt;
! Relationship&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data/scripts/level.c&amp;lt;/code&amp;gt;&lt;br /&gt;
| Global start hook that executes first for every level.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;levelscript&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| Level-specific start hook that executes after the global hook.&lt;br /&gt;
|-&lt;br /&gt;
| [[Update Script|update and updated scripts]]&lt;br /&gt;
| Recurring global or level hooks used during normal gameplay updates.&lt;br /&gt;
|-&lt;br /&gt;
| [[Spawnscript|spawnscript]]&lt;br /&gt;
| Executes for an individual spawn entry when that entry creates an entity.&lt;br /&gt;
|-&lt;br /&gt;
| [[Onspawnscript|onspawnscript]]&lt;br /&gt;
| Executes from the spawned entity&amp;#039;s model after the entity enters play.&lt;br /&gt;
|-&lt;br /&gt;
| [[Endlevelscript|endlevelscript]]&lt;br /&gt;
| Executes when the level finishes, before fade-out and level unloading.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Level]]&lt;br /&gt;
* [[Endlevelscript]]&lt;br /&gt;
* [[Spawnscript]]&lt;br /&gt;
* [[Onspawnscript]]&lt;br /&gt;
* [[Script Overview]]&lt;/div&gt;</summary>
		<author><name>Dcurrent</name></author>
	</entry>
</feed>