Hooks
Functions of a script that the game calls.
A script doesn't run on its own. It defines functions with well-known names and signatures, called hooks, and the game calls them at the right moments. Every hook is optional, a script defines only the ones it needs. A hook with a wrong signature isn't found and is never called, so check the parameter types if a hook seems to do nothing.
Level
- onLevelLoad() — once when the level is loaded, after the global variables of the script are initialized and before the objects of the level are created
- onLevelBegin() — once a little later, when the objects around the starting positions of the players exist
- onLevelReload() — after the level returns to the last checkpoint, when a player died
Every tick
There are 70 ticks in a second, independent of the frame rate. In every tick, the hooks are called in this order:
- onPlayerInput() — for each player, the place to change what the controls of the player do
- onMain() — the main update of the script
- onPlayer() — for each player
- onPlayerDraw() — for each player, adjusts how the player is drawn
Drawing
Drawing hooks are called every frame for the view of each local player and get a jjCANVAS to draw with.
- onDrawLayer1() to onDrawLayer8() — draw into the level at the given layer, from the background at the back to layer 1 at the front
- onDrawAmmo(), onDrawHealth(), onDrawLives(), onDrawScore(), onDrawPlayerTimer() — draw parts of the HUD. Returning
truereplaces the part the game would draw, returningfalsekeeps it.
Events and objects
- onFunction0() —
onFunction0()toonFunction255(), called by Script Callback events of the level - onObjectHit() — when a player or a bullet hits an object with jjOBJ::scriptedCollisions
- onPlayerTimerEnd() — when the timer of a player started by jjPLAYER::timerStart() runs out
- onRoast() — when a player dies
- onCheat() — when a player enters a cheat code
A class implementing jjBEHAVIORINTERFACE becomes a behavior of an object, the game then calls its jjBEHAVIORINTERFACE::onBehave() method every tick, and optionally its jjBEHAVIORINTERFACE::onDraw() and jjBEHAVIORINTERFACE::onObjectHit() methods.
Not supported
The following hooks of other games are never called, a script may define them, but they have no effect:
onChat(),onLocalChat()— chat messagesonGameStart(),onGameStop()— starting and stopping of a multiplayer gameonReceive(),onGetPublicInterface()— communication between scripts and over the networkonHelp()— help pagesonDrawGameModeHUD()— the game never draws this part of the HUD through a script