ForumsProgramming ForumBad Game weapon problem PLZ HELP!

6 2902
staticzone
offline
staticzone
67 posts
Nomad

i have a button with this code

on (release) {
if (money >= 100)
{
money -= 100;
_root.player.goodguy.sword.gotoAndPlay(2);
}
}

But the player has 5 frames in the player mc
and in each of those movie clip frames he does a fight move
i have this on another frame

PHP Code:
function onEnterFrame() {
if (players_turn) {
if (player_attack && player.attack_mc._currentframe == player.attack_mc._totalframes) {
//if the player is attacking
enemy_health -= 20+random(20);
//damage the enemy
player_attack = false;
//the attack is over
players_turn = false;
//the turn is over
player.gotoAndStop(1);
//player look normal again
} else if (player_magic && player.magic_mc._currentframe == player.magic_mc._totalframes) {
//if the player uses magic
enemy_health -= 3*random(20);
//damage the enemy with a bit of risk
player_magic = false;
players_turn = false;
player.gotoAndStop(1);
the problem is that attack_mc and magic_mc have the old sword in it

the only mc that has the new sword is of course _root.player.goodguy.sword.gotoAndPlay(2);

Now how do i go to frame 2 on all those mcs.
the 3 mcs in the player mc have the sword mc in them how in the world do i universally but that sword mc to frame 2 with one button push

thanks

  • 6 Replies
dank
offline
dank
983 posts
Peasant

I'm guessing you have three swords inside goodguy all with the same instance name?

Inside goodguy, player, or what have you, I would recommend making an array of weapons:

var weaponArr:Array = new Array();


And then adding those weapons to the array:
weaponArr[0] = swordMC;
weaponArr[1] = swordMC2;

or for easy reference:
weaponArr["sword1"] = swordMC;
weaponArr["sword2"] = swordMC;


Then you can traverse the array and say:
for(i in weaponArr){// I think this syntax is right. I hven't used it in ages.
i.gotoAndStop(2);
}
staticzone
offline
staticzone
67 posts
Nomad

how do i do arrays and where do i put them?

dank
offline
dank
983 posts
Peasant

I said it:

var weaponArr:Array = new Array();
weaponArr["sword1"] = swordMC;
weaponArr["sword2"] = swordMC2;


It depends on how they will be fitted in your hierarchy. I would probably add them to the player's attributes by putting them in a superclass or assigning them in the player's constructor (or when he's instantiated).
staticzone
offline
staticzone
67 posts
Nomad

@dank

hey dude

for(i in weaponArr){// I think this syntax is right. I hven't used it in ages.
i.gotoAndStop(2);
}

not working...

staticzone
offline
staticzone
67 posts
Nomad

for some reason for(i in weaponArr){// I think this syntax is right. I hven't used it in ages.
i.gotoAndStop(2);
} not working anyone know why?

clipmaster3
offline
clipmaster3
104 posts
Nomad

I don't think your syntax is right
the only way I know of to use a for loop is for(initial, condition, increment)
so if I wanted to trace the numbers 1 - 5
var i:Number;
for(i = 1; i <= 5; i++)
{
trace(i);
}

Showing 1-6 of 6