How do I make double-tap weapon swap keys?

Get help using Construct 2

Post » Tue Jun 27, 2017 4:38 pm

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:

Image

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?
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Jun 27, 2017 6:26 pm

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
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Tue Jun 27, 2017 6:48 pm

Message: Semoreh can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
You could also cascade the Else statements like this maybe ? :)
https://www.mediafire.com/?gvkoknmv52q26bn
B
5
Posts: 24
Reputation: 282

Post » Tue Jun 27, 2017 7:45 pm

Thank you both, those are very helpful examples!
B
18
S
9
Posts: 103
Reputation: 1,817


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests