Picking randomly, in the list

Get help using Construct 2

Post » Sun May 04, 2014 5:14 pm

Here is the list of number. 1,2,3,4. To pick one of them randomly, I can simply type in the action window like "int(random(0,4))+1", or "choose(1,2,3,4)". Now, player unlocks some objects, and now the list of number changed : 1,2,3,4,7,10,16. Now what should I do? The list can be changed with any number, and the size of the list also varies. What I'm thinking is like "choose(list)" but I have no idea how to make it work.
B
23
S
8
G
1
Posts: 172
Reputation: 2,780

Post » Sun May 04, 2014 5:35 pm

Look at the RandomArray. viewtopic.php?t=63557&start=0
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sun May 04, 2014 5:41 pm

blackhornet wrote:Look at the RandomArray. viewtopic.php?t=63557&start=0


Thanks for the help, but this is a little bit different case. The list ifself is not randomly generated. It has to be controlled.
B
23
S
8
G
1
Posts: 172
Reputation: 2,780

Post » Sun May 04, 2014 6:08 pm

My bad. What you can do is have your values in an Array and use the RandomArray as an index into your array.

Edit: you actually do even need the random array. Just use random() to index into your array, based on the number of indices. Depends on what you want.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494


Return to How do I....?

Who is online

Users browsing this forum: Euduardo, Kin, mikehive, ratboy3, tinhofiel and 37 guests