Weapon swap

Hello guys. I have a problem with swapping weapons with one button. I have a variable that turns my weapons on, but each is hooked to a separate key. I want to be able to cycle through my weapons with one button. Like 1press 1st weapon, second press 2nd weapon and so on. Here is a pic of my graph:

Please help! :slight_smile:

Hey there,

Enums are pretty much like arrays of integers (bytes actually), but they have a friendly name. In your case, you have (if you set it up in order in the screen) something like this:

0 = Shotgun
1 = Assault Rifle
2 = Granade launcher
3 = Sniper Rifle
4 = Rocket launcher

So what you have to do is, whenever you press the key you want to get to the next weapon, to add +1 to your Weapon Type (but only if you are not on the last index, e.g. you’re not in rocket launcher; otherwise you will be in index “5” which is empty). So you’ll have to:

  1. When you press a key (e.g. mouse wheel up), check if we are in the last item.
    1.A) If we are NOT in the last item, add +1 to the enum.
    1.B) If we are in the last item, reset the enum (get back to 0).

I made a simple set up with a similar enum, hope this helps.

Edit: sorry, the comment in the branch is wrong, it’s the opposite: Are we NOT in the last index?

This is exactly what I needed and it 100% works! Thank you very much LHutz!!!

remember the opposite when going in reverse direction, if we are the first set us to last, else subtract one from the index.

Thanks guys!