Randomly chooses one of up to 16 arguments.


GML Code Example

choose(val0, val1, val2... val15);

Argument Description
val0... val15 An input value that can be string, integer, variable or constant.

Returns: One of the given arguments.


Sometimes you want to specify something other than numbers for a random selection, or the numbers you want are not in any real order or within any set range. In these cases you would use choose() to generate a random result. For example, say you want to create an object with a random sprite at the start, then you could use this function to set the sprite index to one of up to 16 sprites.

NOTE: This function will return the same value every time the game is run afresh due to the fact that GameMaker: Studio generates the same initial random seed every time to make debugging code a far easier task. To avoid this behaviour use randomize at the start of your game.


GML Code Example

sprite_index = choose(spr_Cactus, spr_Flower, spr_Tree, spr_Shrub);
 hp = choose(5, 8, 15, 32, 40); name = choose("John", "Steven", "Graham", "Jack", "Emily", "Tina", "Jill", "Helen");

The above code uses choose to set a number of properties for the instance.

No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here