-
Notifications
You must be signed in to change notification settings - Fork 29
Actions
dgcor edited this page May 15, 2021
·
2 revisions
Actions can be used on button clicks, keyboard inputs, or timed events in the game to perform some game action.
Actions are identified by their name
.
Here is a list of all the actions supported by DGEngine:
https://github.com/dgcor/DGEngine/blob/master/src/Parser/ParseAction.cpp
param1
- First value. Can be bool, string, int or float value.
param2
- Second value. Should be the same type of param1
. Undefined behaviour otherwise.
then
- Action to execute if comparison is true
.
else
- Action to execute if comparison is false
.
{
"name": "if.equal",
"param1": "|game|musicVolume|",
"param2": 0,
"then": { "name": "audio.stop", "id": "main" },
"else": { "name": "audio.play", "id": "main" }
}
Other conditional actions:
!= / if.notEqual
> / if.greater
>=
< / if.lower
<=
{
"name": "if.fileExists",
"param1": "ui_art/title.pcx",
"then": { "name": "load", "file": "ui/loadMain.json" },
"else": { "name": "load", "file": "ui/dataMissing.json" }
}
Checks if a file in the game's search path exists and executes the appropriate action.
{
"name": "switch",
"param": "{1}",
"case": [
{
"value": "Warrior",
"action": { "name": "image.setTextureRect", "id": "heros", "rect": [0, 0, 180, 76] }
},
{
"value": "Rogue",
"action": { "name": "image.setTextureRect", "id": "heros", "rect": [0, 76, 180, 76] }
},
{
"value": "Sorceror",
"action": { "name": "image.setTextureRect", "id": "heros", "rect": [0, 152, 180, 76] }
}
],
"default": { "name": "image.setTextureRect", "id": "heros", "rect": [0, 228, 180, 76] }
}
Compares the various vaues with param
and executes the appropriate action or default
if no value is equal.