Removing randomized items from list

0 favourites
  • 3 posts
From the Asset Store
Template for scrollable list, fully documented in comment and video
  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can use this plugin.

    Do a search on RandomArray and RandomArray2 for examples.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)