HomeIndex

Game System Callbacks

The following functions are called by the system in response to various events. These should never be called directly. Most of these functions then pass control to other functions that are meant to be modified with game logic. For example: The system callback _clickedAt() calls clickedAt() and any game logic should be placed there.
_initRoom(room)
Called only once when the room is inited.
This function then calls room.init().
_initObject(object)
Called only once when the object is inited.
This function then calls object.init(). It also sets up door verbs if object.door_verbs is set and then registers all verbs found in the object.
_enterRoom(room, stage)
Called when the room is entered.
Based on the stage, this function calls room.preEnter(), room.enter() and room.postEnter().
_exitRoom(room, stage)
Called when exiting a room
This function calls room.exit().
_enterObject(object)
Called for each object when entering a room.
Called after room.preEnter() but before room.enter()
If the object is a trigger and has trigger code, it is added and enabled.
Sounds defined with a object.sound are started, after which object.enter() is called. Then objects that have a state variable are set to the last frame of that animation.
If the sound is a FMOD spatially aware, it won't be heard more than 500 pixels away (by default). The can be changed in FMOD.
_enterObject(object)
Called for each actor when entering a room.
This is also called when an actor is placed in the current room.
_exitObject(room, stage)
Called for each object or actor when exiting a room.
This function calls object.exit() then stops any sound playing that is using object._soundid.
_keyDown(key, flags)
Called when a key goes down.
This function calls keyDown() and all game related logic should happen in there. The parameter flags holds the modifier keys such as MOD_SHIFT and MOD_CONTROL and can be checked using
if (flags&MOD_SHIFT) { ... }
There is no built in functionality for key repeats.
_keyUp(key, flags)
Called when a key comes up.
For most situations you only need to monitor _keyDown()
_actorArrived(actor)
Called when an actor reaches their final destination.
This function is not called as the actor walks around walkboxes and the actor might not stop close to where they were told to walk. If the room is exited while an actor is walking, they will not get this callback. This also calls the optional actor.arrived().
execSentence(actor, verb, noun1, noun2=null)
Called to execute a sentence and, if needed, start the actor walking.
If actor is null then the selectedActor is assumed. If the actor has to walk, the verb code will be called from _actorArrived.
cancelSentence(actor)
Cancels any sentence queued for the actor
If actor is null then the selectedActor is assumed.
inputOff(code)
Turns the input off, runs the code, and then back on
The cursor will also turn off during this time. It should be used for short sequences you don't want the player to interrupt.
inputOff(@{ actorWalkTo(selectedActor, toiletHandle) breakwhilewalking(selectedActor) })
cancelAllInteractions()
Cancels all drags and sentences.
_hoverObject(state, object, room_pos)
Called when an object is hovered over.
The state will be HOVER_ENTER, HOVER_LEAVE, or HOVER_LOITER. The function is responsible for creating the text that appears at the cursor.
_clickedDownAt(screen_pos, flags)
Called when the screen is clicked or touched.
It called on click-down unless it's a touch interface, then it's on touch-up.
clickedAt() and room.clickedAt() are also called by this function.
If a button is clicked on, this callback will not happen. See imageButton() for more information about buttons.
_clickedUpAt(screen_pos, flags)
Called when the mouse button is let up.
_clickedDragAt(screen_pos, flags)
Called when the mouse is moved with the button down.
_startSayline(actor, text)
Called when sayLine text needs to be displayed.
Return an image of the text.
_doneSayline(actor)
Called when the actor's sayLine is done.
_triggerSound(actor,sound)
Called when an actor or object animation triggers a sound
_pauseGame(state)
Called when the game is paused by the window going out of focus
Also called after the pauseGame(YES|NO) is called. This is typically used for a pause key.
_gameFocus(state)
Called when the game gains or looses focus.
_quitGame()
Called when the game wants to quit.
Return true if it's OK, or false if the scripts want to avoid the quit or handle it themselves.