PDA

View Full Version : [AS2] Array with no specific order


IamFace
04-15-2009, 08:49 PM
Hey all,
I'm wondering if anyone knows how to check an array to see if it includes a number of items, but in no specific order?
I'm building a game, where depending on the scenario, you drag specific items to an area of the stage. At first I was simply adding each item dragged into an array, then at the end checking to see if that array matched one I had previously created (to see if they were in the correct order).
Everything works great, until the client decided they wanted them in any order, as long as they are all in there.
For example:
You need to drag item1, item2, and item3. The array does not have to be [item1, item2, item3], it can be in any order, like [item3, item1, item2], whatever. I need to check to see if all the items are included. Is there a way to do this? I've never seen if so and would like to learn :)
Thanks!

CyanBlue
04-15-2009, 09:06 PM
You could simply sort the array when you need to test if it contains certain items, or make a temporary array if you cannot modify the original array, and then use that to compare to see if it contains the items you need... ;)

FYI, I have moved this thread to Gaming and Game Development forum... Please post all the game related questions here so that other people can get benefit from yours... Thanks...

ASWC
04-15-2009, 09:39 PM
yeah like this:
var array:Array = ["hello",7,8,9,23];
var array2:Array = [8,9,23,7,"hello"];
trace(array.sort(Array.DESCENDING));//hello,9,8,7,23
trace(array2.sort(Array.DESCENDING));//hello,9,8,7,23