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
46
S
13
G
3
Posts: 279
Reputation: 4,631

Post » Fri Aug 25, 2017 11:59 pm

ImageImageImage
B
71
S
22
G
274
Posts: 3,827
Reputation: 151,297

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
47
S
13
G
1
Posts: 85
Reputation: 3,239


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests