This content has been marked as final. Show 7 replies
well you 'kind of' have the right idea here - but there's alot more to it than that i afraid. first of all what is the size of your grid - so many columns by so many rows? this will be the determining factor in how you store the information.
secondly, yeah you want to use an array to store item locations, even if there isn't one present, and then you check a 2 dimensional array to find the correct location and see if there is an item currently stored at that location. and if you do use an array in this way - you will not need to iterate through the array to find an item - you can 'point' to the location by using a little math to find the position in relation to the given input.
also, i'm afraid the syntax above isn't quite right :( just fyi.
If all the x and y locations are placed into a two dimensional object array, the array can be shuffled and then just place the objects in consecutive order to the x,y positions in the shuffled array since they will then be random.
Just an example. This will place images randomly and will guarantee you never have a duplicate and avoids all that messy if..else stuff.
These comments are all very helpful. Something I forgot to mention is that there are certain places on the grid where I don't want to place a movie clip. Is there a way for an array to do this?
I used nested for loops to define the grid positions because it was easy. The downside is that it creates every spot on the grid. At the end of the day, what you want is a two dimensional array containing the x and y coordinates of all the grid points that you would like to place an object on. There are a few different ways to do that. The first would be probably the simplest and just push all the points onto the array that are valid. Another way would be to put in some conditionals in the for loops that don't push the point if it is a certain point you don't want. Yet another way is to make the full array and then later cut out individual points of the array.
However you decide to get there, you should end up with the same result. Personally I would go with option one. It might take more lines of script but it involves no logic so is easy to do.
Once that array is created with all the valid x and y points, shuffle the array and start placing objects.
So in that script I posted, only lines 2 thru 6 would need adjustment.
And here is a simple example
Thanks for all the help!