How do I pick random value from array without repeating

Get help using Construct 2

Post » Fri Aug 25, 2017 10:44 pm

I'm attempting to fill a column of 4 squares with color. Once all 4 are filled, I move on to the next column.

I'm picking random values from an array by using
Code: Select all
array.at(round(random(0,3)))
to pick which square to fill but the problem is it will repeat values and I don't want it to do that. I want it to only pick 4 times and then move on.

Should I delete them as I pick them?
B
44
S
13
G
1
Posts: 267
Reputation: 3,555

Post » Fri Aug 25, 2017 11:59 pm

ImageImageImage
B
71
S
22
G
248
Posts: 3,759
Reputation: 138,069

Post » Sat Aug 26, 2017 10:47 am

bclikesyou wrote:I'm attempting to fill a column of 4 squares with color. Once all 4 are filled, I move on to the next column.

I'm picking random values from an array by using
Code: Select all
array.at(round(random(0,3)))
to pick which square to fill but the problem is it will repeat values and I don't want it to do that. I want it to only pick 4 times and then move on.

Should I delete them as I pick them?


That's what I would do: if I wanted to keep the array of random numbers, I'd copy the array first, and then pick-and-pop the array as I go along.
B
42
S
12
G
1
Posts: 74
Reputation: 2,992


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests