How do I change instance variable on keypress

Get help using Construct 2

Post » Fri Nov 20, 2015 10:32 pm

Hey,

I've decided to mess around with construct again. I'm having troubles with a menu.

I've got this sprite called menu_option with instance variable option. The initial value is 'new'

I've got conditions

key board right pressed, and menu_option = 'new': set menu_option option = 'load'
key board right pressed, and menu_option = 'load': set menu_option option = 'exit'
key board right pressed, and menu_option = 'exit': set menu_option option = 'new'

This is doing nothing. The option variable never switches from new no matter how many times I click right.

Any ideas?

Thanks,
Jeremy.
B
7
S
2
Posts: 92
Reputation: 663

Post » Fri Nov 20, 2015 10:37 pm

Are you using the same case? "New" vs "new"?
B
55
S
28
G
19
Posts: 1,520
Reputation: 25,540

Post » Fri Nov 20, 2015 10:52 pm

yup. It's working now from new to load... but load to exit does nothing. I'll show a screenshot.

Image
B
7
S
2
Posts: 92
Reputation: 663

Post » Fri Nov 20, 2015 11:07 pm

The events are looping on themselves. When it's "new" it becomes "load", then even 8 is true, so it becomes "exit" and then event 9 is true, so it becomes "new" again. All happens in a single loop so you don't notice it

I think if you reverse the event order it should work. For a better solution, you should have a timer so there's a small delay before the user can change the option again
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,209

Post » Fri Nov 20, 2015 11:09 pm

This is a common mistake. Don't isolate your events like this, as event 7 is setting the conditions for event 8 which runs next, which sets the conditions for event 9, which runs next which sets option right back to "new" again. Have a single On key press, with subevents, for decoding, using Else between each to guarantee that only one ever gets processed at a time.

On Right arrow pressed
--->option="new -> Set option = "load"
---> Else option="load"->Set option = "exit"

etc...
ImageImageImage
B
71
S
20
G
189
Posts: 3,533
Reputation: 107,840

Post » Fri Nov 20, 2015 11:25 pm

Thanks for the help guys. I can see what you're saying about it looping through all the conditions. Having trouble with the else statement. I've tried below, but doesn't work..

Image
B
7
S
2
Posts: 92
Reputation: 663

Post » Fri Nov 20, 2015 11:37 pm

Actually this is working perfect like this. Must have been because the debugger was open, or cache needed cleared. Not sure. Does the buttons not register sometimes when debugger is open? Maybe it was trying to us the arrows to jump through text inputs in there, or something.

Works awesome. Thanks for the help guys :)
B
7
S
2
Posts: 92
Reputation: 663


Return to How do I....?

Who is online

Users browsing this forum: gamarros, imhotep22, Nimothar, senecaa, yuji567 and 6 guests