-
Notifications
You must be signed in to change notification settings - Fork 4
Events
JasXSL edited this page Jan 25, 2017
·
2 revisions
XOBJ allows you to use linkset-wide events. Events are different than direct method calls in that any script can parse them. These are good when you need multiple scripts to receive data from a single call, without needing to send a callback. For an example when your HP changes in a game, sending an HP or status event might be handy.
To have a script listen to events within a linkset, add at the top of your script #define USE_EVENTS and create the following function:
onEvt(string script, integer evt, list args){}
- Script is the module that raised the event, ex: "got Status"
- evt is the event ID defined in the raising script's header file. Ex: StatusEvt$resources
- args is a list of arguments tied to the event, ex: [100, 50, 25]
- First off, go to the header file for the module you want. Ex:
C:\lsl\myProject\classes\my Module.lsl - Add an event definition:
#define myModuleEvt$helloWorld 1 // (str)message - Outputs a message on state_entry - Within state_entry of your "my Module" SL script, add
raiseEvent(myModuleEvt$helloWorld, "Hello world!") - Note how the arg sent in raiseEvent is a random variable. If you want to send a list, convert it to a JSON array:
raiseEvent(myModuleEvt$helloWorld, llList2Json(JSON_ARRAY, ["Argument A", "Argument B"]))
Note: Event definitions have to be a 0 or positive integer, since there are built in standard events using a negative number