Limit amount of bullets available

Get help using Construct 2

Post » Sat Feb 18, 2012 9:23 pm

Hi everyone, a quick question which I cant find an answer for and fear i am being monumentally stupid.

In the game I am building you have two main weapons, left mouse button fires bullets, right mouse button fires missiles.

I want to limit it so that you only have 3 missiles and when they are used you cant fire anymore... Can anyone tell me how to do this or point me to where its explained.

Thank you in advance for any help.
P.s. Have played with a lot of game making tools in the past year+ and this one is truly the best one I have encountered. Hoping I can use it from now on.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Sat Feb 18, 2012 9:34 pm

This is the type of thing variables are extremely useful for! You can set up a variable, either a private one belonging to the player or a global one, to keep track of the missiles. The initial value can be set to 3, or however many you want to have at the start.

Every time you click the right mouse button, check the value of the variable; if it's greater than zero, meaning you have ammo, fire a missile and subtract one from the variable, but if it's zero, you ran out, so don't do anything.

If you have trouble implementing that idea, I could whip up a quick example to show you how it works.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Sat Feb 18, 2012 9:54 pm

hi, thanks, that's what I thought.

I have already set a global variable in exactly the way you said, but I cant work out how to set it so that it checks if the variable is zero and if it is stops you from firing so a quick example of that would be very handy.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Sat Feb 18, 2012 10:03 pm

http://dl.dropbox.com/u/19702035/bullet.capx

Here you go! It's a VERY quick example, but it illustrates the principle pretty simply.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Sat Feb 18, 2012 10:08 pm

Ah I see now, you can combine two events into one, that makes sense.
Thank you, I should be able to add that without difficulty now.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Sat Feb 18, 2012 10:12 pm

No problem. Don't hesitate to ask if you have any more questions!
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Wed Mar 07, 2012 9:32 am

I was having a major problem trying to figure this out, thanks so much for posting and answering guys.
B
2
Posts: 1
Reputation: 402


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 25 guests