How do I Chang weapons with scroll Mouse wheel ?

Get help using Construct 2

Post » Thu Jan 07, 2016 4:25 am

I have 4 weapons that include Pistol, Shotgun, Cross Bow and Flame thrower. Once I collect one of these weapons it begins the scroll wheel action adding one to a global variable called Switchweapons and if Switchweapos variable go's beyond 4 it resets back to 0 and if it go's below 0 it sets back to 4. The issue that I am having is it adds to this variable to switch weapons but how can I make it not switch if I don't have the weapon?
basically I only want to be able to scroll to 3 if i only have collected the flame thrower and only change to pistol when I scroll, so on and so forth .

pistol will always be active.
B
8
Posts: 14
Reputation: 332

Post » Thu Jan 07, 2016 4:52 am

If you kept an array for the weapons and which ones are active, you could just make a search that goes up or down (depending on which way the scroll wheel was turned) and it keeps searching until it finds an active weapon. That way it'll just skip the gaps.

So some 'current_weapon' value and a 'search' value which is set to on when the scroll wheel turns. Make 'current_weapon' go up by one, check in the array if that's an active weapon. If it is, set 'search' to zero to end the search. If not, add another point to 'current_weapon'. If it resets at 4 and if the pistol is always active, then if it finds no other weapons the search will end at the pistol.
B
48
S
14
G
4
Posts: 184
Reputation: 5,438

Post » Thu Jan 07, 2016 1:44 pm

I have not figured out arrays XD .. This sounds like it would work but I have not messed with Arrays yet So once I figure out how to use them I will try this out.
B
8
Posts: 14
Reputation: 332

Post » Thu Jan 07, 2016 3:55 pm

Is there something that can explain how to do something like this ?
B
8
Posts: 14
Reputation: 332

Post » Fri Jan 08, 2016 4:01 am

Check the manual and see if you can figure how to add an array (hint:double click on the layout) and then in a start of layout event use a for loop to assign random values to the array, then look at the array contents in debug run.

If you can't figure that, come back and ask. Good luck!
B
48
S
14
G
4
Posts: 184
Reputation: 5,438

Post » Fri Jan 08, 2016 5:13 am

I have an array and if you collide with a weapon it adds that value to the array. So lets say I collide with Shotgun it will add into the array 0 shotgun and if I collide with another weapon lets say Crossbow in the array it will say now
0 Crossbow
1 Shotgun
so each weapon will get pushed up to the top

Then I have an instance variable set in the array that changes each time you scroll the mouse wheel up and down
if this instance variable = 0 it will be pistol animation set if it =1 it will be shot gun animation set So I still run in to the problem where if I have just the pistol and scroll it will not change animation because I have not collected another gun it will not shoot because the variable has changed .

Hopefully I have explained this all ... I will see about giving this for loop a try.
B
8
Posts: 14
Reputation: 332

Post » Fri Jan 08, 2016 1:56 pm

Yep still having trouble
B
8
Posts: 14
Reputation: 332

Post » Thu Jan 14, 2016 3:54 am

The way I'd do it is not to use push, just fixed positions for each weapon. So you might have

0. pistol
1. crossbow
2. shotgun

If they walk over a shotgun, then change the value AT position 2 in the array by increasing it.

For scrolling through weapons, if I was scrolling up the list (going up the numbers), I'd maybe have a while statement that increments the current weapon value and if the new weapon ammo amount is >0 the while statement terminates.
B
48
S
14
G
4
Posts: 184
Reputation: 5,438


Return to How do I....?

Who is online

Users browsing this forum: bigezy80, mchulet, mrline, tetuan, TRMG, Yahoo [Bot] and 10 guests