getting random values from an array

Get help using Construct 2

Post » Sat Apr 25, 2015 8:29 pm

I want to get three random values from a one dimension array, without any repeating value. It's easy to get one random value by creating a random number but how do I create second and third random numbers without te risk of getting the same value before?

In fact what I'm trying to do is creating an npc dialogue system in which there are 10 chat topics but the game randomly selects three of these. So the player will select a chat subject among these three. Can you think of a different and better approach to carry out this in Construct 2?
B
3
Posts: 3
Reputation: 181

Post » Sat Apr 25, 2015 11:05 pm

You could make it a 2D-array and if you get a value at X2 then you set X2Y1 to "picked" or something. Or you create another array where you save the already picked values or you create 3 additional variables and save the value u get in var1, the second in var2 and so on and everytime u get a value randomized u check the variables if that value is already picked.

So many ways..
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sun Apr 26, 2015 12:17 am

ImageImageImage
B
71
S
21
G
232
Posts: 3,696
Reputation: 129,868


Return to How do I....?

Who is online

Users browsing this forum: Leef, tarek2 and 25 guests