Events

From Bitfighter
Revision as of 00:22, 3 August 2013 by Kaen (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

Robots and levelgens can register to be notified of certain game events. When the event occurs, a specific function in the script (termed a "callback" function) is invoked. This lets a script perform some action in response to these events.

For a complete list of Events and their callback signatures, see the Event enum in the API documentation.

Example

Subscribing to an event is the same for robots and levelgens: you call bf:subscribe . Here is a simple example using the MsgReceived event which is available to both robots and levelgens:

function main()
  bf:subscribe(Event.MsgReceived)
end
-- Whenever an event occurs which a script is subscribed to, Bitfighter will
-- run the function named after that Event.
-- For the `MsgReceived` Event, the name must be `onMsgReceived`
function onMsgReceived(msg, player, isGlobal)
  print(player:getName(), " said: ", msg)
end