Triggers are created automatically when you add an Action to a Trigger.
For example you can create a Trigger that draws a filled circle using this code:
ON MyTrigger DRAW ELEMENT:Earth FILLEDCIRCLE 100 100 10
You can execute this code using the EXEC command:
EXEC MyTrigger
If you want to add another Action to a Trigger simply add this line:
ON MyTrigger DRAW ELEMENT:Earth FILLEDCIRCLE 200 200 10
If you execute this Trigger again you it will draw two filled circles.
If you save a MyTrigger in a .bs2 file and include this file several times you can get a problem. If the file is included two times every action is added to the triggers two times. So you should use REMOVETRIGGER before defining a Trigger. The file should look like this: MyTrigger.bs2
REMOVETRIGGER MyTrigger ON MyTrigger DRAW ELEMENT:Earth FILLEDCIRCLE 100 100 10 ON MyTrigger DRAW ELEMENT:Earth FILLEDCIRCLE 200 200 10
Now you can include this file many times.
You can also create Triggers by using { }. To create MyTrigger you can write:
TRIGGER MyTrigger {
DRAW ELEMENT:Earth FILLEDCIRCLE 100 100 10
DRAW ELEMENT:Earth FILLEDCIRCLE 200 200 10
}
BS2 automatically translates this to:
REMOVETRIGGER MyTrigger ON MyTrigger DRAW ELEMENT:Earth FILLEDCIRCLE 100 100 10 ON MyTrigger DRAW ELEMENT:Earth FILLEDCIRCLE 200 200 10
The closing } must always have a own line.
This style can not be nested! “ON triggerabc TRIGGER { … }” will be the same as “TRIGGER { … }”.
Do NOT use this style if you send commands to BS2 over network!
This Trigger is Called when the Cursor is over the Sandbox and a mousebutton is pressed.
If DRAWSOLID is 1 then DRAW doesn't skip Pixels on fast mousemovements. If DRAWSOLID is 0 it can skip pixels.
This is the same as DRAW with DRAWSOLID = 0.
A mousebutton was released over the Sandbox.
The X Icon on the BS2 windows or ALT+F4 was pressed.
The statusinformation wants to be updated.
The BS2 window was resized.
This is the order BS2 executes Triggers:
WHILE (EXIT == 0) {
EXEC PREPHYSICS
IF (PHYSICS) calculating physics
EXEC POSTPHYSICS
EXEC PRETIMER
running timers
EXEC POSTTIMER
EXEC PREUPDATESCREEN
SET PREVIEW 1
EXEC DRAW
SET PREVIEW 0
updating screen
EXEC POSTUPDATESCREEN
running keys
running mousegestures
}
KEY_a is called when the “a” key was pressed.
KEYUP_a is called when the “a” key was released.
KEYREPEAT_a is called every few milliseconds while you hold “a”.
HOLDKEY_a is called every frame you hold “a”. This also works if your press several keys.
List of available keys:
Have a look at these variables: Draw Variables