Equivalent of GameMakers’s function choose

Godot Version



In GameMaker there is a function called choose(val0, val1, val2… max_val);
See the [manual] ← link to the choose function description from GameMaker.

You can do something like this:
hp = choose(5, 8, 15, 32, 40);
name = choose(“John”, “Steven”, “Graham”, “Jack”, “Emily”, “Tina”, “Jill”, “Helen”);
And it will return a random number (in the case of hp) or string (in the case of name) picked from the available numbers/strings.

Is there something similar in Godot?

Or is the best way to go about this to make an array and use the pick_random function in Godot?

If you have your elements in an array like this

var array = [“John”, “Steven”, “Graham”, “Jack”, “Emily”, “Tina”, “Jill”, “Helen”]

you can pick one of them with the function pick_random()

var random_choice = array.pick_random()

Link to the docs


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.