Skip to main content
Zefirofire
Participant
August 10, 2015
Answered

How could I create a 'party' array or code

  • August 10, 2015
  • 1 reply
  • 296 views

Hi,

I still have some problem thinking about my code and how I should do it. (Beginner here!)

The question is that I want to create a 'party' member code for 10 heroes or more with all separated stats.

I wonder if I should create an array that I send it everywhere or there is an another solution, like a temporary files that stock up and save.

The array should look like this:

lvl 1 of the array: Party section

lvl 2 of the array: name,xp,attack,defence, lvl of the character.

Exemple : [['rodolf',1300,3,4,78],['Baaaaa',1301,4,3,79],['mukmuk',103,2,3,80], etc...]

I know that I can pop when a character die or leave the party, but I feel that its not a good solution for all of this. Cause the party is a very active variable and can change a lot of times. So I need your help to guide me! Please!

Thank you for reading my problem and try to help me!

This topic has been closed for replies.
Correct answer kglad

use an object:

var obj:Object={};

updateParty('rudolf',1300,3,4,78);

function updateParty(nameS:String,_xp:int,_attack:int,_defense:int,_lvl:int):void{

obj[nameS]={xp:_xp,attack:_attack,defense:_defense,lvl:_lvl};

}

function retrieveParty(nameS):Object{

return obj[nameS];

}

///////////////

// then if you want to retrieve the lvl of mukmuk, use:

trace(retrieveParty('mukmuk').lvl);

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 10, 2015

use an object:

var obj:Object={};

updateParty('rudolf',1300,3,4,78);

function updateParty(nameS:String,_xp:int,_attack:int,_defense:int,_lvl:int):void{

obj[nameS]={xp:_xp,attack:_attack,defense:_defense,lvl:_lvl};

}

function retrieveParty(nameS):Object{

return obj[nameS];

}

///////////////

// then if you want to retrieve the lvl of mukmuk, use:

trace(retrieveParty('mukmuk').lvl);

Zefirofire
Participant
August 11, 2015

Yeah its sound pretty good! I forgot that I could use object too! Thank you a lot

kglad
Community Expert
Community Expert
August 11, 2015

you're welcome.