Difference between revisions of "LevelScripts"
From Wolfire Games Wiki
m |
m (Improved formatting) |
||
Line 3: | Line 3: | ||
Level scripts have a hierarchy, and hook functions inside them are called in a specific order: | Level scripts have a hierarchy, and hook functions inside them are called in a specific order: | ||
− | 1. level.as | + | 1. level.as |
− | 2. the level script specified in a given level, if any | + | 2. the level script specified in a given level, if any |
− | 3. the level script hooks defined for each loaded mod, if any | + | 3. the level script hooks defined for each loaded mod, if any |
− | + | ||
+ | == List of hook functions == | ||
+ | |||
+ | // Required - called when the level is first loaded | ||
+ | void Init(string level_name) { | ||
} | } | ||
− | + | // Required - Note: Not called on per-mod level scripts. | |
+ | // TODO: What is this this used for? | ||
+ | bool HasFocus() { | ||
return false; | return false; | ||
} | } | ||
+ | // Required - hook to allow a level-specific script to regularly update itself on each game tick. Only called if the game is not frozen/paused. Can be empty | ||
// Note: Only for a level-specific level script. Don't define in per-mod level scripts or in the base level script | // Note: Only for a level-specific level script. Don't define in per-mod level scripts or in the base level script | ||
− | void Update() { | + | void Update() { |
} | } | ||
+ | // Required - hook to allow the base level script and per-mod level scripts to regularly update themselves on each game tick. is_paused is 0 if not paused, and 1 if paused. Can be empty | ||
// Note: Only for the base level script, and per-mod level scripts. Don't define in level-specific level scripts | // Note: Only for the base level script, and per-mod level scripts. Don't define in level-specific level scripts | ||
− | void Update(int is_paused) { | + | void Update(int is_paused) { |
} | } | ||
− | + | // Required - hook to allow the level script to draw a custom GUI. Can be empty | |
+ | void DrawGUI() { | ||
} | } | ||
− | + | // Optional - additional hook called as a second pass after the entire first set of DrawGUI hooks have been called | |
+ | void DrawGUI2() { | ||
} | } | ||
− | + | // Required for base level script and for per-mod level scripts. Hook to handle resizing a custom GUI when the game window has been resized | |
+ | void SetWindowDimensions(int new_width, int new_height) { | ||
} | } | ||
− | + | // Optional - called when a hotspot inside the level is entered by a moving object. Note: called after any "HotspotExit" hook is called. | |
+ | // TODO: What is str? | ||
+ | void HotspotEnter(string str, MovementObject @mo) { | ||
} | } | ||
− | + | // Optional - called when a hotspot inside the level is exited by a moving object. Note: called before any "HotspotEnter" hook is called. | |
+ | // TODO: What is str? | ||
+ | void HotspotExit(string str, MovementObject @mo) { | ||
} | } | ||
− | + | // Required for base level script, Optional for level-specific level script, and per-mod level scripts. Hook to allow messages to be passed between level scripts, or from moving object scripts to level scripts | |
+ | void ReceiveMessage(string) { | ||
} | } | ||
− | + | // Optional - hook to allow receiving incoming network communication in the game client. Called when a network TCP packet has been receieved | |
+ | void IncomingTCPData(uint socket, array<uint8>@ data) { | ||
} | } | ||
− | + | // Required for base level script, not called on level-specific level script, or per-mod level scripts. | |
+ | // TODO: What is this used for? | ||
+ | void SaveHistoryState(SavedChunk@ chunk) { | ||
} | } | ||
− | + | // Required for base level script, not called on level-specific level script, or per-mod level scripts. TODO: What is this used for? | |
+ | void ReadChunk(SavedChunk@ chunk) { | ||
} | } |
Revision as of 07:35, 25 April 2017
This page describes the hook functions that are called by the game inside level scripts, and what order level script functions are called
Level scripts have a hierarchy, and hook functions inside them are called in a specific order:
1. level.as 2. the level script specified in a given level, if any 3. the level script hooks defined for each loaded mod, if any
List of hook functions
// Required - called when the level is first loaded void Init(string level_name) { }
// Required - Note: Not called on per-mod level scripts. // TODO: What is this this used for? bool HasFocus() { return false; }
// Required - hook to allow a level-specific script to regularly update itself on each game tick. Only called if the game is not frozen/paused. Can be empty // Note: Only for a level-specific level script. Don't define in per-mod level scripts or in the base level script void Update() { }
// Required - hook to allow the base level script and per-mod level scripts to regularly update themselves on each game tick. is_paused is 0 if not paused, and 1 if paused. Can be empty // Note: Only for the base level script, and per-mod level scripts. Don't define in level-specific level scripts void Update(int is_paused) { }
// Required - hook to allow the level script to draw a custom GUI. Can be empty void DrawGUI() { }
// Optional - additional hook called as a second pass after the entire first set of DrawGUI hooks have been called void DrawGUI2() { }
// Required for base level script and for per-mod level scripts. Hook to handle resizing a custom GUI when the game window has been resized void SetWindowDimensions(int new_width, int new_height) { }
// Optional - called when a hotspot inside the level is entered by a moving object. Note: called after any "HotspotExit" hook is called. // TODO: What is str? void HotspotEnter(string str, MovementObject @mo) { }
// Optional - called when a hotspot inside the level is exited by a moving object. Note: called before any "HotspotEnter" hook is called. // TODO: What is str? void HotspotExit(string str, MovementObject @mo) { }
// Required for base level script, Optional for level-specific level script, and per-mod level scripts. Hook to allow messages to be passed between level scripts, or from moving object scripts to level scripts void ReceiveMessage(string) { }
// Optional - hook to allow receiving incoming network communication in the game client. Called when a network TCP packet has been receieved void IncomingTCPData(uint socket, array<uint8>@ data) { }
// Required for base level script, not called on level-specific level script, or per-mod level scripts. // TODO: What is this used for? void SaveHistoryState(SavedChunk@ chunk) { }
// Required for base level script, not called on level-specific level script, or per-mod level scripts. TODO: What is this used for? void ReadChunk(SavedChunk@ chunk) { }