are if then statements in the "classic" sense possible in construct2?
suppose i want event A to occur when the spacebar is pressed and not occur again provided X condition is true
if spacebar is pressed and variable == false
then spawn object and set variable == true
else if spacebar is pressed and variable == true
then do nothing
if spawned object is destroyed
then set variable == false
i've tried setting global variables and using boolean, but i am not seeing a way restrict the event from occurring until the spawned object is destroyed
also, isn't there an event that says "do nothing"? if so, where can i find it?
thanks a million
You should check the beginner's guide to C2 and specially page 4 that deals with events.
This is the base of C2 and what you can relate to as "if" structures. You can also "read" events/conditions as "when".
The actions are the "then" part.
You don't need a "do nothing" action, you just don't test it.
Also "blank condition" is usable, but will act as a "every tick" condition.
Develop games in your browser. Powerful, performant & highly capable.
So, according to the guide:
...In short, an event basically runs like this:
Are all conditions met?
---> Yes: run all the event's actions.
---> No: go to next event (not including any sub-events).
System -> every tick -> check value of variable/boolean
(value == true => do remaing stuff in this event)
(value != true => skip the remaining stuff and go to next event)
I'll give it a shot and let u know how it turns out
You almost got it.
You don't need to have a condition "every tick" and do a test after.
Just do your test.
So it'd give something like :
System -> Compare variable.
(value == true => do remaing stuff in this event and test its subevents)
For boolean it is almost the same, except boolean will be instance variables. So you have to select their parent object first.
Sprite -> Is boolean instance variable set
Ok, so that leads to the question- should the comparison be in 2 separate events
System -> compare variable/boolean (variable == true)
Do this stuff
System -> compare variable (variable != true)
Do this stuff
Or is it a more of a nested approach
System -> compare variable (variable == true)
compare variable (variable != true)
Do nothing here; go to next event
So in theory it would check the 1st condition in the event, if it is != true continue to the next line and check that or does it automatically skip the remaining stuff in an event once the system encounters a "none truth"?
I am beginning to grasp the syntax
If it is relevant to test the fact that the boolean is from a different value then in the first test, use two events.
Let's pretend your boolean variable is used to check the fact that a sprite is supposed to be moving or not.
Sprite.is boolean instance variable set (value = true)
-> Action move sprite
By default it would mean that it is not supposed to move when the boolean is false.
In that case you don't need to test if the value is false as the "resulting action" would be nothing.
Save yourself some useless tests.
But now, in the case the boolean stands for a direction (if it is true, the sprite goes right, if false, it goes left).
Condition Sprite.boolean instance var is set
-> Action Sprite go right (Sprite.x = Sprite.x + 60*dt)
Condition Sprite.boolean instance var is not set
-> Action Sprite go left (Sprite.x = Sprite.x - 60*dt)
thanx a million kyatric