|
-
DOT-INVADER
again, i have some array troubles...
ok, i have *again* some arrays troubles...
here's an example of what i have:
Code:
label = new Array()
label["rrr"] = ["money", "a", "a", "a"];
label["sss"] = ["money", "a", "a", "a"];
label["ttt"] = ["gold", "a", "a", "a"];
label["uuu"] = ["money", "a", "a", "a"];
label["vvv"] = ["gold", "a", "a", "a"];
label["www"] = ["gold", "a", "a", "a"];
label["xxx"] = ["money", "a", "a", "a"];
label["yyy"] = ["gold", "a", "a", "a"];
label["zzz"] = ["silver", "a", "a", "a"];
^ here's a collection of arrays that is quite similar to what i need for my game. the value that i want to work with is the value [0]. in this example, it can be "money", "gold" or "silver".
now, i want to create another array that will sort all these [0] values, and group them depending on this value; so there will be an array holding all the array's names having "money" as [0], another "gold" and another "silver"; as a result, 3 new arrays.
...sorry if it's not clear enough. basically, i want to check the collection of array above and look for all the ones that have "money" as [0] for example.
since i cannot work with a for loop combined with the label.length (because they are not called label[0], label[1], label[2] etc... the length isn't working), how can i do that?
> my solution is to have another array holding all "rrr", "sss", "ttt" ... "zzz" values and perform a for loop thanks to it. something like that:
Code:
label_check = ["rrr", "sss", "ttt" ... "zzz"];
BUT i have something like 40/50 arrays each time, so sorry i absolutely don't want to rewrite them all that way!!! ^^
is there a solution? thanks a lot if you can help...
-
Senior Member
something like this might do?
code: label = new Array()
label["rrr"] = ["money", "a", "a", "a"];
label["sss"] = ["money", "a", "a", "a"];
label["ttt"] = ["gold", "a", "a", "a"];
label["uuu"] = ["money", "a", "a", "a"];
label["vvv"] = ["gold", "a", "a", "a"];
label["www"] = ["gold", "a", "a", "a"];
label["xxx"] = ["money", "a", "a", "a"];
label["yyy"] = ["gold", "a", "a", "a"];
label["zzz"] = ["silver", "a", "a", "a"];
money = new Array();
gold = new Array();
silver = new Array();
for(i in label) {
if(label[i][0] == "money") {
money.push(label[i])
} else if (label[i][0] == "gold") {
gold.push(label[i])
} else {
silver.push(label[i])
}
}
trace(money)
trace(gold)
trace(silver)

[m]
-
DOT-INVADER
!!!of course!!!
where was my head? i was so concentrated with the for loop that i forgot to test or think about the for...in loop! duh!
thanks a lot mbenney, i'll try it tomorrow... (sure, it has to work like that). it's a LOT of time saving for me here, wow.
again, thanks.
-
Senior Member
np matey =)
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
|