How do I make double-tap weapon swap keys?

0 favourites
  • 4 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hello, I've got a logic problem that's causing me to scratch my head but I'm not sure what exactly I would need to do to solve it. In my game the player can obtain upgrades to their arsenal that are the same weapon type (dual pistols, multiple shotguns, and so on). I'd like it if I could combine the weapon select buttons so that the player doesn't have to reach across their keyboard to switch. For example:

    Press 3 once, your character pulls out the single shotgun.

    Press 3 with the single shotgun out, your character pulls out the double barrel.

    Press 3 with the double barrel out, your character pulls out the automatic shotgun.

    I've tried to emulate it here:

    But obviously this doesn't work because the 'else' statement causes weapon 5 to never be selected. What would the proper way of coding this be?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It does select 5 but changes to 3 further down due to Construct 2's top down structure. There are probably many ways to fix this but when I'm doing this kind of cycling I lock out the top to bottom picks so only one is ever picked per press.

    See in the image how I added the variable 'pick', this allows it to select only one weapon every time 3 is pressed. Then when a weapon is selected on the right 'pick' is set to 1 which then locks it out for the remainder of the checks. Then I reset 'pick' to 0 at the end after all possible weapon checks.

    https://www.dropbox.com/s/xku0snl9lmaqzrx/cycle.jpg?dl=0

  • You could also cascade the Else statements like this maybe ? <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" />

    mediafire.com

  • Thank you both, those are very helpful examples!

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