How do I Chang weapons with scroll Mouse wheel ?

0 favourites
  • 8 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • 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.

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

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

  • Is there something that can explain how to do something like this ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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!

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

  • Yep still having trouble

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

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