Randomly populating an array with specific values?

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I'm really curious how you would accomplish the following:

    Picture a grid - 6x6. You want to randomly populate the 36 individual cells of the grid from a list of 36 specific values.

    I'm seeing a two-dimensional array to hold the cell values, but thoughts on setting them randomly, making sure each listed value is only used once?

    Contributors to the forums never cease to amaze me with their ingenuity and talent. So - How would you do it?

    Thanks in advance. Any help is appreciated.

    • Scott
  • I like to take a visual approach. Given that you're putting the values in a 2d grid, I imagine you may eventually create sprites to visualize it. So why not create the sprites with 36 animation frames for each value and have a animation speed of 0. You can either create the grid of sprites in the editor or use events to make it. The events would like the following.

    Start of layout:

    --- destroy sprite

    Start of layout:

    for "x" from 0 to 5:

    for "y" from 0 to 5:

    --- create sprite at (loopindex("x")*32+200, loopindex("y")*32+200)

    Start of layout:

    for each sprite ordered by random(1) ascending:

    ---- set animation frame to loopindex

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • another variant:

    <img src="http://666kb.com/i/cjwp6exg9s6mzweav.png" border="0" />

    s000.tinyupload.com/index.php

  • Hey ROJOhound and mindfaQ,

    I just wanted to say thank you for your very helpful input! Sorry for the delay (stupid actual job!).

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