# Suggestion: Simple Choice Function

Discussion and feedback on Construct 2

### » Thu Dec 01, 2011 5:45 pm

Hello, Dcrew here suggesting a feature!

Gamemaker has this function, Now I don't use game-maker.. But this is very useful!

A Choice Function!

So say if I put:

Set Global Variable 'Hmmm' to Choose(1,2,3,4,5,6,7,8,9)

It will loop this peice of code for the ammount of "," times

And it will choose any of those numbers randomly.

Another example:

Set Global Variable 'EG' to Choose(1,-1)

then It would choose either 1 or -1, at random!!

This is very useful, and I really hope to see it!

P.S: You could do it with strings to; Set Global String 'Hello' to Choose("hi","hello","hey","sup")
B
18
S
4
G
5
Posts: 226
Reputation: 4,087

### » Thu Dec 01, 2011 6:04 pm

You can actually do this with a combination of other expressions:

float(tokenat("1,3,5,7,9", int(random(5)), ","))

where "1,3,5,7,9" is a comma-separated list of numbers and the 5 in random(5) is the number of items in the list.
Scirra Founder
B
414
S
245
G
92
Posts: 25,198
Reputation: 200,327

### » Thu Dec 01, 2011 6:23 pm

[QUOTE=Ashley] You can actually do this with a combination of other expressions:

float(tokenat("1,3,5,7,9", int(random(5)), ","))

where "1,3,5,7,9" is a comma-separated list of numbers and the 5 in random(5) is the number of items in the list.[/QUOTE]

Thanks, But I do recommend adding the choice function still, for people who dislike complex methods, or don't understand how to use it.

Don't get me wrong, I understand that fully! But I'd prefer just to type "choose(1,3,5,7,9)"
B
18
S
4
G
5
Posts: 226
Reputation: 4,087