Difference between revisions of "LevelScripts"

From Wolfire Games Wiki
Jump to: navigation, search
(List of hook functions)
Line 1: Line 1:
 
Level scripts allow you to set up level-wide code that will get run, regardless of what characters, items, and hotspots exist in that level.
 
Level scripts allow you to set up level-wide code that will get run, regardless of what characters, items, and hotspots exist in that level.
 +
 +
=== Script Tiers ===
  
 
There are multiple tiers of level scripts:
 
There are multiple tiers of level scripts:
Line 12: Line 14:
 
# One per-level script ('''<script>something.as</script>''', defined by '''Edit -> Set Level Script...''')
 
# One per-level script ('''<script>something.as</script>''', defined by '''Edit -> Set Level Script...''')
 
# Multiple per-mod level hook scripts ('''<LevelHookFile>something.as</LevelHookFile>''', inside mod.xml)
 
# Multiple per-mod level hook scripts ('''<LevelHookFile>something.as</LevelHookFile>''', inside mod.xml)
 +
 +
=== Documentation ===
 +
 +
Documentation of the code that you can call inside a level script is available in an automatically generated file on your hard drive:
 +
 +
# '''On Windows''': <code>My Documents\Wolfire\Overgrowth\aslevel_docs.h</code>
 +
# '''On Mac''': <code>~/Library/Application Support/Overgrowth/aslevel_docs.h</code>
 +
# '''On Linux''': <code>~/.local/share/Overgrowth/aslevel_docs.h</code>
  
 
== List of Data/Scripts/level.as hook functions ==
 
== List of Data/Scripts/level.as hook functions ==

Revision as of 21:20, 24 July 2017

Level scripts allow you to set up level-wide code that will get run, regardless of what characters, items, and hotspots exist in that level.

Script Tiers

There are multiple tiers of level scripts:

  1. level.as (in the file Data/Scripts/level.as). The engine will call into this script for every level in the game. You can override this script in mods, but it is best to only do this as a last resort, since this can make your mod incompatible with other script mods that also override the same file.
  2. The <script>per_level_script.as</script> XML tag inside a level XML file. This can be changed in the UI under Editor -> Top Bar -> Edit -> Set Level Script.... You can override this script in your mods, but it requires you to make a per-level change, and only one such script can be active for a given level.
  3. The <LevelHookFile>all_level_script.as</script> XML tag inside a mod XML file. You have to manually add this XML tag the mod.xml that you make for your mod. Functions in this script are run for every level in the game, and every mod can add their own level hook script. The disadvantage to it is that you can't as easily override default level script behavior. For the most part, changes in this file are limited to adding on additional behavior.

The order that the engine calls into level scripts is as follows:

  1. level.as (in the file Data/Scripts/level.as)
  2. One per-level script (<script>something.as</script>, defined by Edit -> Set Level Script...)
  3. Multiple per-mod level hook scripts (<LevelHookFile>something.as</LevelHookFile>, inside mod.xml)

Documentation

Documentation of the code that you can call inside a level script is available in an automatically generated file on your hard drive:

  1. On Windows: My Documents\Wolfire\Overgrowth\aslevel_docs.h
  2. On Mac: ~/Library/Application Support/Overgrowth/aslevel_docs.h
  3. On Linux: ~/.local/share/Overgrowth/aslevel_docs.h

List of Data/Scripts/level.as hook functions

Required in Data/Scripts/level.as

These functions are required, and must be present in level.as. If you override that file in your mod, you must include all of these functions.

 void Init(string level_name) { }
 // Called when the level is first loaded.
 // Be careful, this may be called before some objects or script params are present in the level.
 // It is most useful for setting initial values for file-scope angelscript state.
 void Update(int is_paused) { }
 // Called regularly by the engine so you can perform work, or detect that the game is paused.
 // It may be useful to do initialization once in this function, if you need objects or level script params to be present.
 void ReceiveMessage(string message) { }
 // Called when level-wide messages have been sent by the engine, or by objects in levels.
 // Objects in levels (such as characters or hotspots) can send this using level.SendMessage("some message string");.
 // Parameters can be sent by separating them with spaces, and putting quotes around parameters that might contain spaces,
 //   then using the TokenIterator object.
 void HotspotExit(string str, MovementObject @mo) { }
 // Triggered when any hotspot is exited by a movement object
 void HotspotEnter(string str, MovementObject @mo) { }
 // Triggered when any hotspot is entered by a movement object
 void DrawGUI() { }
 // Serves as an update function for script-defined GUIs
 void SetWindowDimensions(int width, int height) { }
 // Allows a script-defined GUI to resize itself when the window gets resized
 void SaveHistoryState(SavedChunk@ chunk) { }
 // Allows the level script to save extra undo state
 void ReadChunk(SavedChunk@ chunk) { }
 // Allows the level script to retrieve extra redo state
 bool HasFocus() { return false; }
 // Old unused function.
 // Reserved, though, so be careful to just make this function return false, and not use it for anything

Optional in Data/Scripts/level.as

These functions are optional, but will be called if they are present in level.as.

 void IncomingTCPData(uint socket, array<uint8>@ data) { }
 // Optional - Networking hook for when network data comes in over a socket you've created
 void DrawGUI2() { }
 // Optional - A second pass for updating script-defined GUIs, in case you need to do something with two passes (e.g. layout)