Using the same key to toggle a state.

0 favourites
  • 4 posts
From the Asset Store
State Machine
$10.99 USD
State Machine is a great tool for managing the state of anything in your game.
  • Hello all,

    Im trying to get my each around this event based programming and I can't seem to solve this problem of using the same keyboard button to toggle a state on or off.

    Attached is my implementation:

    http://dl.dropbox.com/u/5760424/lol.capx

    What it is suppose to do:

    When the black square moves (using the w,a,s,d keys) to a grey square and presses the space button (while facing the square) a message pops up and the black sprite is frozen until the interaction message is terminated with the space button again. However I am unable to terminate the interaction message with the space button and I am temporary using the control button to terminate the interaction message. This is because the space triggers both popup and termination of the message at the same time. This is where I need help. If you don't get what I mean please download the file from the dropbox link.

  • Use the boolean instance variable that you've already set up for the player: 'interact1'

    keyboard 'space' - toggle boolean 'interact1'

    • player boolean 'interact1' true? - do stuff
    • player boolean 'interact1' false? - do other stuff

    or something like that.

    Although, I haven't gone through your example very closely... as long as you only toggle it once per tick, you shouldn't have any problems.

    edit: Here you go.

  • Toggle? Simple:

    + On some key pressed

    • somevariable = 1 - variable
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, I'm so blind I completely missed the 'toggle' action. This is exactly what I was looking for.

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