Shuffle images outside a form

Sep 30, 2016

Hi! I have 4 pairs of cards arranged in a matrix like a memory game. I would like that every time that the match starts, the cards take a different place inside that matrix. I know the Shuffle option in a form but I would like to use that outside a form.

Does someone knows how to shuffle images in the beginning of a scene?

Thank you in advance!

2 Replies
Dave Cox

I've created some games where I need to shuffle elements. The way I always do this is to place my elements in an array, and then shuffle the order of the array. Of course, you have to use javascript to do this.

Here is the function I wrote to shuffle the array:

function shuffle(array) {
 var elementsRemaining = array.length, temp, randomIndex;
 while (elementsRemaining > 1) {
  randomIndex = Math.floor(Math.random() * elementsRemaining--);
  if (randomIndex != elementsRemaining) {
   temp = array[elementsRemaining];
   array[elementsRemaining] = array[randomIndex];
   array[randomIndex] = temp;
  }
 }
return array;
}

This discussion is closed. You can start a new discussion or contact Articulate Support.