Difference between revisions of "Creating a WorldScript"

From Serious Sam's Bogus Detour
Jump to: navigation, search
Line 1: Line 1:
 +
WorldScripts are units you can place inside of a level that perform some logic. Creating your own world scripts is useful for executing certain scripts in a level.
 +
 +
== The setup ==
 +
 +
This is what the ScriptLink (a default script) looks like:
 +
 +
<pre class="prettyprint">
 +
namespace WorldScript
 +
{
 +
[WorldScript color="176 196 222" icon="system/icons.png;416;128;32;32"]
 +
class ScriptLink
 +
{
 +
SValue@ ServerExecute()
 +
{
 +
return null;
 +
}
 +
}
 +
}
 +
</pre>
 +
 +
This script essentially means: when triggered, do nothing. This is useful for the reason that this script will trigger other scripts that are targeted by this one, without performing any action. In other words, it links scripts together, hence its name.
 +
 +
We store the class in a "WorldScript" namespace, as to not clutter the global namespace too much and to avoid name ambiguities. The name of the class will be the name of the script, as it will be shown in the editor and in the editor view. Use of capital letters is encouraged since in compact script mode, the editor will display the abbreviations of script names instead of their icon. For example, "ScriptLink" will show as "SL".
 +
 +
To indicate that the class is indeed a world script, we add the <code>[WorldScript ...]</code> header, along with a color and an icon. This way the editor will be able to find and display the script. The color is a simple format of <code>r g b</code>, so in the ScriptLink example above, this would be: <span style="width: 1em; height: 1em; background: rgb(176, 196, 222); padding: 2px; border: 1px solid #999;">176 196 222</span>
 +
 
===Functions===
 
===Functions===
 
     void Initialize()
 
     void Initialize()

Revision as of 10:38, 17 July 2017

WorldScripts are units you can place inside of a level that perform some logic. Creating your own world scripts is useful for executing certain scripts in a level.

The setup

This is what the ScriptLink (a default script) looks like:

namespace WorldScript
{
	[WorldScript color="176 196 222" icon="system/icons.png;416;128;32;32"]
	class ScriptLink
	{
		SValue@ ServerExecute()
		{
			return null;
		}
	}
}

This script essentially means: when triggered, do nothing. This is useful for the reason that this script will trigger other scripts that are targeted by this one, without performing any action. In other words, it links scripts together, hence its name.

We store the class in a "WorldScript" namespace, as to not clutter the global namespace too much and to avoid name ambiguities. The name of the class will be the name of the script, as it will be shown in the editor and in the editor view. Use of capital letters is encouraged since in compact script mode, the editor will display the abbreviations of script names instead of their icon. For example, "ScriptLink" will show as "SL".

To indicate that the class is indeed a world script, we add the [WorldScript ...] header, along with a color and an icon. This way the editor will be able to find and display the script. The color is a simple format of r g b, so in the ScriptLink example above, this would be: 176 196 222

Functions

   void Initialize()
   void Update(int dt)
   SValue@ ServerExecute()
   void ClientExecute(SValue@)
   void OnEnabledChanged(bool enabled)
   void DebugDraw(vec2, SpriteBatch&)
   SValue@ Save()
   void Load(SValue@ save)