Event order logic question

Discussion and feedback on Construct 2

Post » Fri Sep 21, 2012 6:01 am

I have the following situation with event order



I would like to understand the difrence in event order and logic of execution in C2 (i know is from up to botom), but in this case (not working sheet) when you klick and 'active'=0 and 'c'=0 then it change them to 1 and in same event, I guess, check if 'active' is 1 and 'c' is 1 so it sets 'active' to 0 but not 'c' so it can't reset conditions ('active'=1, and 'c'=0 can't triger enything). Em i right? Or is it something else in question?

I think that C2 need some nice basic tuts about event logic, I can't always grasp what's accualy happening.
podpathos2012-09-21 06:02:13
B
12
S
2
G
2
Posts: 96
Reputation: 1,583

Post » Fri Sep 21, 2012 6:22 am

Hiya podpathos.

The logic is "falling through" - events are executed one after another, top down to the bottom. The issue you have here is that subevents do not know when you are using them as a switch statement - which is what you're trying to do here. There is no implicit break after a subevent, so Construct just keeps on executing.

Go through your event in question logically with the non-working version:

On any click, C2 does the following comparison:

        if(active == 0 & c == 0) then (active = 1 & c = 1)

Then C2 does the next comparison:

        if(active == 1 & c == 1) then (active = 0)

But we just made that true with the last event! So this event will always execute - and active cannot equal 1.

The solution to this can be what you posted as working - don't place events that are dependant on the outcome of other events below those events. OR you can use local variables. Have a global number, and test with each subevent that that number is 0. If it's not, it won't execute. If it is, execute the action and set the global number to 1. This guarantees only one event will ever execute in a subevent branch.
B
55
S
12
G
8
Posts: 339
Reputation: 9,314

Post » Fri Sep 21, 2012 6:42 am

Thanks man, I see it all much clearer now.
B
12
S
2
G
2
Posts: 96
Reputation: 1,583


Return to Construct 2 General

Who is online

Users browsing this forum: Artpunk, TRMG and 13 guests