Difference between revisions of "Events"
From Bitfighter
(Created page with "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 i...") |
|||
Line 1: | Line 1: | ||
− | Overview | + | = Overview = |
− | Robots and | + | 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 | + | For a complete list of Events and their callback signatures, see the Event enum in the API documentation. |
− | Example | + | = Example = |
− | Subscribing to an event is the same for robots and levelgens: you call bf:subscribe . Here is a simple example using the MsgReceived | + | Subscribing to an event is the same for robots and levelgens: you call <code>bf:subscribe</code> . Here is a simple example using the <code>MsgReceived</code> event which is available to both robots and levelgens: |
<source lang="lua"> | <source lang="lua"> | ||
Line 20: | Line 20: | ||
end | end | ||
</source> | </source> | ||
+ | |||
+ | [[Category:Scripting]] |
Latest revision as of 00:22, 3 August 2013
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