Shuffle content of any Array in your project


Attached Files

The following files have been attached to this tutorial:



Download now 171.86 KB


4,071 visits, 6,284 views



This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Hi there,

For my first tutorial, I'll focus on a trivial thing, shuffle the content of an Array. But with a little trick : this can work with any Array of your project !

I've included the .capx file, feel free to use it if you want/need it.

For this to work you need :

. Registered version of Construct 2

. Knowing how an Array work, if not read Arrays for beginners

. At least one Array or more, with content in it

. Create a Family of your arrays

. One Function

For my example, 2 Array (1 and 2), one Function, one Family Arrays (contains my 2 Array)

So, the first thing to do is initialization

Nothing complicated here.

I've arbitrary choose 10 and 50 for array size, and fill them with values 1..10 and 101..150, but you can fill with another values.

You call the function ShuffleArray to...shuffle an array. You need to pass the UID of the array to be shuffled.

The method

How it works : each value in the array will be swapped with another randomly selected value. You can use another algorithm to shuffle your array, but this way is quick and simple, and do the job.

The "trick" part : you need to pick the array's instance from Arrays Family with the UID given in the Function.Param(0). Then you can set an action Arrays > Set at X

That's all ! You can see the result in the debug inspector by launching the debug layout.

Thanks for reading !



Download now 171.86 KB

  • Order by
Want to leave a comment? Login or Register an account!