Weapon Switching idea?

Get help using Construct 2

Post » Fri Jul 25, 2014 5:05 pm

I have attempted a few different methods for about 5 hours to figure out how to correctly switch weapons using the mouse wheel up or down, and nothing seems to be working correctly. Here is what I have done so far using variables that has worked the best, but still is messed up:

I have a global variable named "Current Weapon". I have 6 different weapon types for my player. Each weapon is essentially tied to 0 through 5 on the "Current Weapon" variable. Each weapon type has global variables as well for ammo on each weapon.

I have one event that does - on mouse wheel up AND Current Weapon less than or equal to 4 - add 1 to Current Weapon

Another event does - on mouse wheel down AND Current Weapon greater or equal to 1 - subtract 1 from Current Weapon

Other events tie the text on screen to which weapon you have scrolled to as long as there is ammo still for that particular weapon. I have a text box used to display what weapon you have scrolled to, and switches as you scroll on the mouse. When you run out of ammo, the text will no longer display with that weapon anymore. But there is still a placeholder or empty slot now when you scroll up or down on the mouse wheel for that weapon and what I have not been able to figure out is how to get the system to only allow me to scroll to those weapons that still have ammo.

This all works and everything as long as I don't run out of bullets for each type, but as soon as I run out the system is essentially scrolling to an empty slot. Practically this jacks up the gameplay since when you are scrolling fast on the mouse wheel trying to get to the next gun and you scroll past the weapon with ammo.

Can someone maybe redirect me to a different method because I cannot see how variables will work correctly for what I am trying to do? It is quite difficult to explain this all in words, but hopefully someone can get the gist of what I am trying to explain.

FYI, recently moved so I don't have internet access on my home PC yet or I would upload some screenshots.
B
13
S
5
G
1
Posts: 119
Reputation: 2,292

Post » Fri Jul 25, 2014 5:34 pm

Okay, I think I get your idea.

First off, I'd stop using the greater than/less than conditionals, they can quickly confuse you. Personally I'd use the clamp expression.

https://www.scirra.com/manual/126/system-expressions

So you have your weapon numbers 1-6, 1 is your lower and 6 is your upper, this means any number lower than 1 (-1,-2,-3 etc.) is going to register as 1, and any number higher than 6 (7,45, 197) is going to register as 6.

The set your mousewheel events, on up +1 to the Current Weapon, on down -1, simple enough.

To limit the selection to guns with ammo is a little trickier, I'd throw an event in there that checks your current ammo every time the Current Weapon value changes, if the value of ammo is 0, +1 to Current Weapon - add an or statement that does the same, but with the conditional of Current Weapon =6, in which -5.

This is off the top of my head, hope it helps.

EDIT//

Just realised this wont really work going down, ideally you'd want to listen for the mousewheel action (up or down) and then base your maths (plus or minus) on that, I'll have a bit of a think, maybe the wait function would help? :oops: This may take a brighter mind than mine!
B
62
S
23
G
10
Posts: 648
Reputation: 10,580

Post » Sat Jul 26, 2014 5:20 pm

@mr e bear the issue hasn't been necessarily the less than or greater than expressions. It is simply the open slots that are created when I run out of ammo on a particular weapon. I am looking into using possibly arrays to do this, but I do not have enough knowledge of those to know if that solution will work either. I'm just about stumped at this point for a solution based on my limited knowledge...Do you or anyone else know if arrays would work for this?
B
13
S
5
G
1
Posts: 119
Reputation: 2,292


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests