if then and boolean

Get help using Construct 2

Post » Mon Oct 10, 2011 8:23 am

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

i.e.

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
B
16
S
2
G
1
Posts: 43
Reputation: 1,473

Post » Mon Oct 10, 2011 10:21 am

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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Mon Oct 10, 2011 5:43 pm

@ kyatric

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).

So...
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

B
16
S
2
G
1
Posts: 43
Reputation: 1,473

Post » Mon Oct 10, 2011 6:06 pm

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)
                                         (value != true => skip the remaining stuff and go to next event)

For boolean it is almost the same, except boolean will be instance variables. So you have to select their parent object first.

Ex:
Sprite -> Is boolean instance variable set
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Mon Oct 10, 2011 9:29 pm

@kyatric

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)
                   Do this stuff
                  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
       
B
16
S
2
G
1
Posts: 43
Reputation: 1,473

Post » Mon Oct 10, 2011 9:39 pm

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.

Condition
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)

DT tutorial
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Wed Oct 12, 2011 5:40 am

thanx a million kyatric
B
16
S
2
G
1
Posts: 43
Reputation: 1,473


Return to How do I....?

Who is online

Users browsing this forum: Artpunk and 20 guests