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:

  1. onPlayerInput() — for each player, the place to change what the controls of the player do
  2. onMain() — the main update of the script
  3. onPlayer() — for each player
  4. 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.

Events and objects

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 messages
  • onGameStart(), onGameStop() — starting and stopping of a multiplayer game
  • onReceive(), onGetPublicInterface() — communication between scripts and over the network
  • onHelp() — help pages
  • onDrawGameModeHUD() — the game never draws this part of the HUD through a script