How do I change instance variable on keypress

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Are you using the same case? "New" vs "new"?

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

  • 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

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

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

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)