This wiki has been moved to into the mediawiki branch.

Difference between revisions of "ScriptingLevel"

From SuperTux
Jump to: navigation, search
(Moved example code from Teleport to here.)
m (changed edit to Level_edit)
Line 21: Line 21:
| Toggle pause
| Toggle pause
! class="method" style="vertical-align: top"| edit(bool editing)
! class="method" style="vertical-align: top"| Level_edit(bool editing)
| Change to/from edit mode
| Change to/from edit mode

Latest revision as of 10:31, 9 December 2015


The Level class provides basic controlling functions for the current level.


An instance named Level is available from scripts and the console. (Note: class and eponymous instance might create potential conflicts – the name of one might be changed eventually)


finish(bool win) Ends the current level. If you set win to true, the level is marked as completed if launched from a worldmap.
Tip: Very useful if you have created a frustrating level and want to, at some point, save the player from agony.
spawn(string sectorname, string spawnpointname) Respawns Tux in the sector sectorname at the spawnpointname spawnpoint.
Exceptions: If sectorname or spawnpointname are empty or the specified sector does not exist, the function will bail out first chance it gets. If the specified spawnpoint doesn't exist, Tux will be spawned at the spawnpoint named main. If this spawnpoint doesn't exist either, Tux will simply end up at the origin (top-left 0, 0).
flip_vertically() Flips the level vertically (i.e. top is now bottom and vice versa). Call again to revert the effect.
Tip: Make sure the player can land on something after the level is flipped!
toggle_pause() Toggle pause
Level_edit(bool editing) Change to/from edit mode



Example code


The following code teleports the player to spawnpoint "main" in sector "underground".

  (script "Level.spawn(\"underground\", \"main\");]]")
  (button #f)
Scripting reference
Ambient sound · Camera · Candle · Display effect · Floating image · Globals · Level · Level time · Path · Platform · Player · Scripted object · Sector · Sound · Text · Thunderstorm · Tilemap · Will-o-wisp · Wind