How do I Shuffle content of any Array every x time?

Get help using Construct 2

Post » Mon Jun 19, 2017 9:15 am

hello everybody..
I have an array content 12 value (12.1.1), How do I Shuffle content of this Array every x time?
B
3
Posts: 4
Reputation: 183

Post » Mon Jun 19, 2017 10:40 am

The way I do it is that I use a 2D array for this. In your case this would be a (12.2.1) size array.

I store the values I want to shuffle at y=1.

At y=0 for each x element of the array I store a random number. Then I sort the array using the x axis as always the element at y=0 will be taken for sorting. Repeat this every arbitrary number of seconds.

Example capx, after 1 second the first random sort will show then the next for values from 0 to 11:

https://www.dropbox.com/s/b3bf1exx745z2 ... .capx?dl=1
B
14
S
4
Posts: 80
Reputation: 960

Post » Tue Jun 20, 2017 9:24 am

@PLOLWA

You can shuffle a 1D array using this technique, using only one event and a local variable:

https://www.dropbox.com/s/thbz3x5ze4lhy ... .capx?dl=0

I've included annotations explaining how it works. Press any key to shuffle. Event 3 does the actual shuffle, the rest is just setup.

You can adapt it for a 2D array by nesting the loop:

https://www.dropbox.com/s/h8pmfmjgfkvu8 ... .capx?dl=0

If you want to shuffle every X seconds swap the Keyboard input for an "Every X seconds" condition.
B
13
S
6
G
2
Posts: 263
Reputation: 2,724


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests