condition not detected?

For questions about using Classic.

Post » Fri Oct 01, 2010 8:22 am

this problem occured when i was trying to make animations for my game.

I created an event "check left arrow is pressed" if it is true then set global variable 'pressed' to '1' ELSE set it to '0'. this condition works correctly, but if I create another condition "Check right arrow is pressed" then set 'pressed' to '1' ELSE set it to '0'. Now, this condition is detected but not the previous one. But if I rearrange the event and place the "left arrow" condition in the last, then it works but not the "right arrow" one.
I tried invert condition instead of ELSE but it didn't work. Tested it on both 0.99.84 and 0.99.91 and same thing happens on both.

here's the cap:
0.99.91 game cap
http://dl.dropbox.com/u/5811650/Infestations/test1.cap
use debug to see the change in value of the variable.
the condition is in the playercontrol event sheet

0.99.84 test cap
http://dl.dropbox.com/u/5811650/Infestations/prob.cap

EDIT: sorry, i think i didn't save the the 0.99.91 cap after adding the condition, i'll add them quickly now
edit 2: 0.99.91 cap replaced
B
9
S
3
G
3
Posts: 366
Reputation: 2,301

Post » Fri Oct 01, 2010 11:00 am

That's a common logical error that occurs because Construct works a little different from our human thinking. Have a look at the flowchart in this thread: [url:3q7nm5pd]http://www.scirra.com/forum/viewtopic.php?f=8&t=6880[/url:3q7nm5pd]

What happens is that if you press the right arrow key, the events do recognize it and change the global to 1, but the event loop hasn't ended yet, so the changes are not reflected. Instead, the next event tells Construct to only change the global (who's current value is 1) to 1, if the left arrow is pressed. But it isn't, you are still in the tick where the right arrow key is down, that's why the global is changed back to 0 and now the the event loop has ended and the changes are reflected.

The solution is the followig:

Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests