Suggestion: Simple Choice Function

Discussion and feedback on Construct 2

Post » 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
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » 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
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » 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
17
S
4
G
5
Posts: 226
Reputation: 4,042


Return to Construct 2 General

Who is online

Users browsing this forum: eli0s, Lof, RageByte and 8 guests