|
-
[F8] Storing ammo variable value
Sorry for the quite general title, I found it quite difficult to explain my problem in a brief way.
Anyway my problem.
I'm currently trying to develop a sniper/fps game (original I know) and have got the basic engine pretty much sorted. I've currently got two weapons that I can swap from. I also have an ammo value set up for one of the two weapons (global variable) and this works. When the ammo gets to 0 it goes to a reload frame. However say I wanted this second weapon to have more ammo, without getting rid of the other ammos value. How would you recommend I do this. My current code is:
PHP Code:
weapons.gotoAndStop("weapon1");
_global.Ammo1 = 10
This oviously sets the ammo value to 10.
PHP Code:
target1.head.onPress = function() {
_global.Ammo1 -= 1
trace(_global.Ammo1);
if (_global.Ammo1<=0){
gotoAndStop("reload");
}
When the enemy movie clip is pressed the ammo value goes down 1, when it reaches 0 it goes to the reload frame.
Now this all works, which I was really chuffed about considering I've not been coding that long, and this seems like a huge feat.
Now I have another weapon, and would like to give this gun a seperate ammo value, without disrupting Ammo1's value. The code for weapon 2 so far is:
PHP Code:
on (keyPress "2"){
trace("2 down");
weapons.gotoAndStop("weapon2");
I imagine I'd set a new ammo global variable, say ammo2, but how would I change which global variable to subtract the ammo from when I click the enemy, and also without getting rid of the ammo1 value?
Please feel free to leave a comment if you need this better explained. I will try my best xD All help is hugely appreciated!
George
Also sorry if this is in the wrong forum section I thought it was probably meant to go in this one as it is directly related to game help, although I understand that it could go in the Actionscript forum...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|