Consequences grammar - mouton5000/DiscreteEventApplicationEditor GitHub Wiki
This is how you should write the consequences in each arc of the graph. When a token goes through an arc, all the consequences are run (see the General overview page for more information). The consequences are executed exactly once per true evaluation by the token of the boolean expression of the arc. Possibly multiple tokens goes through the same arc at the same time and all the consequences are executed in an indifferent order.
Overview of the consequences
A consequence of an arc can
- add, edit or remove a property or a event of the truth database
- add, edit or remove a shape of the graphics
- add a sound
- add a token to any place or remove the current token
- add, remove or edit a variable of the current token
- edit global properties
An arc can contain any number of consequences. Each one must end with ;
.
Here is an example of list of consequences :
add pLikePizza('Me'); add eLaunchEvent('You', 2);
adds a new property calledLikePizza
with one parameter with value'Me'
and one event calledLaunchEvent
with two parameters with respective values'You'
and2
.add pNewElement('value' = X + 2); edit globals('fps', 60); add toAnimation(POSITION=2);
adds a property calledNewElement
with one keyword property with key 'value' and with valueX + 2
whereX
is a variable previously evaluated by the token while it went through the arc ; then it edits the fps of the game to 60 and, finally, it adds a new token to the node with idAnimation
, this new token enters the arc with an existing evaluation of the variablePOSITION
with value 2.edit grTable(id = 34 | color = '44F4F4'); add X;
edits an existing rectangle to the panel of the game and changes it colors to'44F4F4'
, each shape has an id, this one must satisfyid = 34
; then it addsX
, whereX
is an existing evaluated variable, to the current token so that, until this variable is removed, each time the token enters an arc, it enters with an existing evaluation ofX
(it will be evaluated with the current value ofX
).
Arguments (Arithmetic expressions)
Many consequences uses evaluated arithmetic expressions as argument. Those expressions use exactly the same grammar than the arithmetical expression describe in the Boolean expressions grammar page plus one additionnal litteral that will be introduced in the next section of the document.
Manage current evaluation
The current token is associated with an evaluation it carries all along the nodes it visits. This can be seen as a local variable with a scope corresponding to the token. When the token is created, this evaluation is usually empty. See the associated section in this page for more information.
add X
, whereX
is an evaluated variable adds that variable to the evaluation of the token. During the following iterations of the token, the arcs the token goes through can use X as an evaluated variable in their boolean expressions.remove X
, whereX
is an evaluated variable of the evaluation of the token, removes that variable from that evaluation.edit X A
, whereX
is an evaluated variable of the evaluation of the token and where A is an arithmetical expression, change the evaluation of X to the value of A.
@
The self argument The arithmetical expression of the 'edit variable' expression can use an extra symbol: the self argument '@'. This argument means 'the value of X'.
For example edit X @+1
edits the variable X by adding 1 to it.
In that specific case, where X is already evaluated and is associated to a token, using @
has exactly the same effect than using X
.
Manage properties and events
To distinguish the properties and the events, a property name starts with 'p' and an event name starts with 'e'. Then the name contains one capital letter, and then any number (including 0) of alpha numerical character. For example pIsTall, pIsGreaterThan, eMouse2Click, ... Then a property or an event contains a list of arguments and keyword arguments.
Add a property or an event
In order to add a property or an event to the truth database, use the following expressions:
add pNameOfTheProperty(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
, where Ai, Bi, Ci are arithmetic expressions, is interpreted as "add one property in the truth database with name NameOfTheProperty, with n arguments of value Ai and m keyword arguments such that the key is the value of Bj and the argument is the value of Cj".add eNameOfTheProperty(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
adds similarly an event with n arguments and m keyword arguments.
Remove a property
In order to remove a property or an event from the truth database, use the following expressions:
remove pNameOfTheProperty(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
, where Bi are arithmetic expressions and where Ai and Ci are unnamed arguments or arithmetic expressions, is interpreted as "remove every properties in the truth database with name NameOfTheProperty, with n arguments of value Ai (or is ignored if Ai is an unnamed argument) and m keyword arguments such that the key is the value of Bj and the argument is the value of Cj (or is ignored if Ai is an unnamed argument)".remove pNameOfTheProperty(id = A)
, where A is an arithmetic expression, removes the property for which the id is the value of A. It is possible to add arguments and keyword arguments to that expression but all of them will be ignored.- it is not possible to remove an event as an event automatically disappear one iteration after it was created.
Edit a property
In order to edit a property or an event of the truth database, use the following expressions:
edit pNameOfTheProperty(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
, where Bi and Bi' are arithmetic expressions and where Ai, Ai', Ci and Ci' are unnamed arguments or arithmetic expressions, is interpreted as "edit every properties in the truth database with name NameOfTheProperty, with n arguments of value Ai (or is ignored if Ai is an unnamed argument) and m keyword arguments such that the key is the value of Bj and the argument is the value of Cj (or is ignored if Ai is an unnamed argument): the ith-argument of the property is replaced with the value of Ai' and, for every keyword argument with key Bi', replace the arguement with the value of Ci'". Note that if the value of Bi' is not the key of a keyword argument of the property, then the edition is not done. Nevertheless, the keys Bi' should not necessarily be the same than the keys Bi'.edit pNameOfTheProperty(id = A | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
, where A is an arithmetic expression, where Bi' are arithmetic expressions and where Ai' and Ci' are unnamed arguments or arithmetic expressions, edits the property for which the id is the value of A the same way as the previous consequence expression. It is possible to add arguments and keyword arguments to the first part of the expression but all of them will be ignored.- it is not possible to remove an event as an event automatically disappear one iteration after it was created.
Examples
If the truth database contains a property called Level listing heroes with as argument their level and as keyword arguments their names and category: for instance, there are two soldiers called 'Bau' and 'Bui' with respective levels 20 and 22, then pLevel(20, 'Cat' = 'Soldier', 'Name' = 'Bau')
and pLevel(22, Cat = 'Soldier', Name = 'Bui')
are in the truth database with respective ids 10 and 121.
edit pLevel(_, 'Cat' = 'Soldier' | _, Cat= 'Archer' )
edits the two properties and set the keyword arguement 'Cat' from 'Soldier' to 'Archer'edit pLevel(10 | _, Cat= 'Archer' )
edits no property as no property has a level 10edit pLevel('Name' = 'Bau' | _, Cat= 'Archer' )
set the category of 'Bau' to 'Archer'edit pLevel(_, 'Cat' = 'Soldier' | 21)
edits the two properties and set the level to 21edit pLevel(id = 10 | 21)
edits the property of 'Bau' and set the level to 21
It is not possible to set a different value for 'Bau' and 'Bui' using that expression. Thus, for instance increasing the level of the two properties at the same time is not possible. A first way could be to use two different expressions, one for 'Bau' and one for 'Bui'. This is not very user friendly if you have to change the level of many character. To do so, we can use the self argument '@'.
edit pLevel(_, 'Cat' = 'Soldier' | @ + 1)
edits the two properties and increases the level by 1. We would then have in the truth database:pLevel(21, 'Cat' = 'Soldier', 'Name' = 'Bau')
andpLevel(23, Cat = 'Soldier', Name = 'Bui')
The self argument can also be used with strings.
edit pLevel(_ | _, 'Cat' = @ + ' of the order', 'name' = 'Super '+ @)
edits the two properties and change their categories and names. We would then have in the truth database:pLevel(20, 'Cat' = 'Soldier of the order', 'Name' = 'Super Bau')
andpLevel(22, Cat = 'Soldier of the order', Name = 'Super Bui')
. This operation can also be done with variables. However, using the self argument is more efficient and simpler.
Graphics and sound properties
Those properties works the same as the events and classic properties, except that those properties refer to the graphics elements (sprites, lines, ellipses, rectangles, polygons, texts) and the sound currently played.
Those properties have some exclusive keywords that can be used to check and edit the property of the graphics elements associated with. It is also possible to use the id
keyword argument with those properties.
Sprites
A sprite property name starts with 'gs' and is associated with a sprite drawn on the screen. Then, as for the events and the properties the name contains one capital letter, and then any number (including 0) of alpha numerical character. For example gsHero
, gsTREE
, ...
It is possible to add, remove and edit a sprite using the three following consequences:
add gsNameOfTheSprite(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
remove gsNameOfTheSprite(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
edit gsNameOfTheSprite(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
The exclusive keywords of the sprite properties are:
filename
for the name of the file of the sprite.x
for the abscissa.y
for the ordinate.z
for the z-index.rotate
for the rotation angle of the sprite.scale
for the scaling parameter of the sprite.
There is no quotes surrounding those keywords.
Lines
A line property name starts with 'gl' and is associated with a line drawn on the screen. Then the name contains one capital letter, and then any number (including 0) of alpha numerical character. For example glWall
, glSeparator
, ...
It is possible to add, remove and edit a line using the three following consequences:
add glNameOfTheLine(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
remove glNameOfTheLine(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
edit glNameOfTheLine(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
The exclusive keywords of the line properties are:
x1
for the abscissa of the first point.y1
for the ordinate of the first point.x2
for the abscissa of the second point.y2
for the ordinate of the second point.z
for the z-index.width
for the width of the line.color
for the color of the line.
There is no quotes surrounding those keywords.
Ovals
An oval property name starts with 'go' and is associated with an oval drawn on the screen. Then the name contains one capital letter, and then any number (including 0) of alpha numerical character. For example goSun
, goHead
, ...
It is possible to add, remove and edit an oval using the three following consequences:
add goNameOfTheOval(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
remove goNameOfTheOval(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
edit goNameOfTheOval(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
The exclusive keywords of the oval properties are:
x
for the abscissa of the center.y
for the ordinate of the center.w
for the width of the oval.h
for the height of the oval.z
for the z-index.width
for the width of the oval.color
for the color of the oval.
There is no quotes surrounding those keywords.
Rectangles
A rectangle property name starts with 'gr' and is associated with a rectangle drawn on the screen. Then the name contains one capital letter, and then any number (including 0) of alpha numerical character. For example grHouse
, grBox
, ...
It is possible to add, remove and edit a rectangle using the three following consequences:
add grNameOfTheRectangle(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
remove grNameOfTheRectangle(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
edit grNameOfTheRectangle(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
The exclusive keywords of the rectangle properties are:
x
for the abscissa of the upperleft corner.y
for the ordinate of the upperleft corner.w
for the width of the rectangle.h
for the height of the rectangle.z
for the z-index.width
for the width of the rectangle.color
for the color of the rectangle.
There is no quotes surrounding those keywords.
Polygons
A polygon property name starts with 'gp' and is associated with a polygon drawn on the screen. Then the name contains one capital letter, and then any number (including 0) of alpha numerical character. For example gpTemple
, gpRock
, ...
It is possible to add, remove and edit a polygon using the three following consequences:
add gpNameOfThePolygon(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
remove gpNameOfThePolygon(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
edit gpNameOfThePolygon(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
The exclusive keywords of the polygon properties are:
xi
, where i is an integer, for the abscissa of the i-th point of the polygon.yi
, where i is an integer, for the ordinate of the i-th point of the polygon.z
for the z-index.width
for the width of the polygon.color
for the color of the polygon.
There is no quotes surrounding those keywords.
Texts
A text property name starts with 'gt' and is associated with a text drawn on the screen. Then the name contains one capital letter, and then any number (including 0) of alpha numerical character. For example gtScore
, gtName
, ...
It is possible to add, remove and edit a text using the three following consequences:
add gtNameOfTheText(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
remove gtNameOfTheText(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm)
edit gtNameOfTheText(A1, A2, ..., An, B1 = C1, B2 = C2, ..., Bm = Cm | A1', A2', ..., An', B1' = C1', B2' = C2', ..., Bp' = Cp')
The exclusive keywords of the text properties are:
text
for the text that is currently displayed on the screenx
for the abscissa of the text.y
for the ordinate of the text.z
for the z-index.color
for the color of the text.fontName
for the name of the font of the text.fontSize
for the size of the font of the text.
There is no quotes surrounding those keywords.
Sound
It is possible to play a sound or a music with the following consequence:
add sound(A)
, where A is an arithmetic expression corresponding to the name of the file of the sound.
Edit a global property
Three global properties can be edited during the execution : the current fps, the width and the height of the screen.
- edit globals(fps, A), where A is an arithmetic expression, edit the current number of fps to the value of A.
- edit globals(screenWidth, A), where A is an arithmetic expression, edit the current width of the window to the value of A.
- edit globals(screenHeight, A), where A is an arithmetic expression, edit tthe current width of the height to the value of A.
Manage the tokens
Add a token
A token can be added with the following consequence:
add toNameOfANode(VAR1 = A1, VAR2 = A2, ..., VARn = An)
, where VAR1, VAR2, ..., VARn are (not necessarily evaluated) variables names and where A1, A2, ..., An are arithmetic expressions, creates a new token and put it in the node of nameNameOfANode
. This node will have an evaluation: the variable VARi will be evaluated with the value of Ai.
Remove a token
It is possible to remove the current token (the one executing the current set of consequences) with:
remove token