select
Returns an argument selected by n. This is similar to selecting an element from an array, except the elements are arguments.
// Display a dialog box.
n = show_question("Will you click Yes?");
// Select a string based on the button clicked.
show_message("You clicked " + select(n, "No", "Yes"));
In the above example, show_question()
returns either 0
or 1
,
selecting "No"
or "Yes"
respectively.
- select(n, choice0, choice1, choice2, ...)
- Returns an argument selected by n.
COPY/// @func select(n, choice0, choice1, choice2, ...)
///
/// @desc Returns an argument selected by n. If n equals 0,
/// the first choice is returned. The selection value
/// is clamped to return a valid argument. If n is
/// not a real value, undefined is returned.
///
/// eg. select(bool, "False", "True");
///
/// @param {real} n selected array index
/// @param {any*} choiceN possible values to return
///
/// @return {any*} selected choice
///
/// GMLscripts.com/license
function select()
{
if (!is_real(argument[0])) return undefined;
return argument[clamp(argument[0] + 1, 1, argument_count - 1)];
}
Contributors: xot
GitHub: View · Commits · Blame · Raw