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?
Posts: 6
Reputation: 189

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: ... .capx?dl=1
Posts: 85
Reputation: 1,195

Post » Tue Jun 20, 2017 9:24 am


You can shuffle a 1D array using this technique, using only one event and a local variable: ... .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: ... .capx?dl=0

If you want to shuffle every X seconds swap the Keyboard input for an "Every X seconds" condition.
Posts: 515
Reputation: 4,472

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 7 guests