This topic was published by Jarret Buse and viewed 846 times since "". The last page revision was "".
- Topics - 25
To get into scripting, the best way to learn is to jump right into the language. Super Tux uses a language called Squirrel. For information on Squirrel, there will be two downloads available in an EPUB format which can be viewed on a Nook or an Android tablet using an E-Book Viewer. The first EPUB is "SuperTux Scripting.epub" and the second is "Squirrel 3.0 Reference Manual.epub".
NOTE: SuperTux v0.3.5 uses Squirrel v2.2.4
The "SuperTux Scripting.epub" e-book shows the specific commands for SuperTux. The e-book "Squirrel 3.0 Reference Manual.epub" shows the Squirrel language and how it is used. Download both of these e-books and use them as a reference as we go through the scripts.
The first script we will cover is the Initialization Script (InitScript). When a level starts, the InitScript is run. Many things could be placed into the InitScript. Be aware that the InitScript is run before any Bad Guys are enabled on the level. If music is set for the Ambient Sound, it will play while the script is running.
First, let's look at a script placed into a level called "InitScript.stl" which will be available for download (http://dcjtech.info/wp-content/uploads/2015/10/InitScript.stl_.zip). If you right-click on the "main" tab and select "Properties", you will be allowed to change the properties for the Sector. The Properties are shown in Figure 1.
NOTE: Each level (STL file) can be made up of many sectors. The tab on the screen called "main" is one sector. To add a Sector, right-click on a tab or in the rectangular boxes, which contain the tabs, and select "New".
You can see the fourth line is for setting up an InitScript. Pressing the "Edit Script" button will allow you to manage a script when the level initializes.
NOTE: Technically, the script is run whenever Tux is spawned. Tux is also spawned after he is killed and starts over again so be aware the InitScript will be performed again.
The scripts we are using for the spawning of Tux, we will deal with the spawning event. Spawning is any event where Tux "appears" at a starting point. We will go over the initial event when the level starts and when Tux is transported to another spot in a Sector or to another Sector.
Take a look at the InitScript.stl file by opening it in the SuperTux 2 Level Editor. You should see something similar to Figure 2.
As you can see from the tabs, there are two sectors. One sector, by default, is named "main" (usually leaving the name alone is best). The second sector is named "NextSection". The initial spawning point is above ground on the "main" sector called "main" (also default so do not rename it). A spawn-point is placed underground on the "main" Sector and it is called "mainunder". The second Sector has a spawn point called "NS1". The names can be whatever you may like, but try to leave the default Sector and Spawn-Point as "main".
So, how do we handle so many Spawn-Points? On the top level of the Sector "main" there is a button. The button has the following script code:
Level.spawn( "main","mainunder" );
The code here is to spawn Tux to a Spawn-Point called "mainunder" on the Sector "main". The underground button has the script:
Level.spawn( "NextSection","NS1" ); Effect.set_black( true );
Here, the spawn is to the Sector named "NextSection" and the Spawn Point named "NS1". The spawning is followed by an Effect where the screen is set to black. The value sent to the effect is "true" to make the screen black. If the line is removed, the Sector called "NextSection" will be shown and the Sector "main" will be visible in the background.
NOTE: When switching Sectors, be aware that the screen needs to be cleared to so no residual graphics are left. Another option is to fade the screen to black by the command "Effect.fade_out(time-in-seconds);" and "Effect.fade_in(time-in-seconds);". Whichever is fine, but check each transportation of Tux to verify the fading works and the screen is not left black.
Look over the two Sectors and you will see that the on the Sector "main" the transportation is caused by the use of a switch. On the Sector "NextSection" the transportation is caused by a ScriptTrigger. Here, it appears that Tux walks into a door and is suddenly back to the initial spawn point on "main".
It may not seem like much, but it shows the use of transporting Tux to different spots, the use of two Effect commands, and the basic use of InitScript scripting.
- Supertux Level Editor Articles (List) - http://dcjtech.info/topic/gaming/#supertux
Attachments:You must be logged in to view attached files.