Removing randomized items from list

Get help using Construct 2

Post » Tue Aug 25, 2015 3:59 pm

Hello all,

I have a 3x3 grid with sprites containing numbers 1-9. I'd like for each square of the grid to randomly have one of the numbers, but not have any repeats.

My first thought was having a 3x3 array with the values 1-9, having a global variable randomly pulling a value from the array, telling the system to spawn the corresponding sprite in the first grid square (ex: if 3, spawn sprite 3 at 1,1), telling the array to remove the pulled value, then repeat this for each subsequent grid square, but I guess my knowledge of arrays is lacking, because I cannot seem to make that work.

Currently I'm manually "randomizing" the squares with a global variable set to random and several possible configurations for the system to choose from, but it's not truly random and the number of choices are far from what a true randomize could create. So any help would be greatly appreciated.
B
6
Posts: 10
Reputation: 272

Post » Tue Aug 25, 2015 4:16 pm

You can use array with a 8 wide x and remove each number from the array as it gets picked. And when the array is empy you simply rebuild the array and start over.

So when array is empty > set x 0 to 1
set x 1 to 2
set x 2 to 3

etc etc.
B
55
S
24
G
13
Posts: 767
Reputation: 12,575

Post » Tue Aug 25, 2015 5:27 pm

You can use this plugin. https://github.com/nutmix/RandomArray2

Do a search on RandomArray and RandomArray2 for examples.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494


Return to How do I....?

Who is online

Users browsing this forum: Armench, brunopalermo, dand, hcporto, TRMG and 29 guests