Randomly populating an array with specific values?

Get help using Construct 2

Post » Sat Dec 07, 2013 6:41 am

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
B
9
S
3
G
1
Posts: 12
Reputation: 760

Post » Sat Dec 07, 2013 10:16 pm

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
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Sun Dec 08, 2013 12:27 am

another variant:

http://s000.tinyupload.com/index.php?file_id=55819694936437762201mindfaQ2013-12-08 00:27:45
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri Dec 13, 2013 6:11 am

Hey ROJOhound and mindfaQ,

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

- Scott
B
9
S
3
G
1
Posts: 12
Reputation: 760


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest