Returns the median (middle number) of up to 16 real value arguments.


GML Code Example

median(val1, val2, ... val15);

Argument Description
val0 ... val15 The values to compare.

Returns: Real


This function returns the median of the input values, that is, the middle value. When the number of arguments is even, the smaller of the two middle values is returned and the function can have up to 16 arguments which must all be real values. This means that, for example, median(43, 12, 25, 19, 6) would return 19 as it is the middle value between all the rest.


GML Code Example

x = median( 0, x, room_width );
 y = median( 0, y, room_height );

This will stop the player from exiting any side of the room, by using median as a clamp. If the player, for instance, moves to the left of the room boundary, its x will be smaller than 0. This will mean the middle number of the first of the medians will be 0, so the player will be jumped to (0,y).

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