array_last

This function returns the last element in the given array, i.e. the last element at index array_length(array)-1.

This function does not modify the array. To remove the last element of the array while reading it, use array_pop.

 

Syntax:

array_last(array);

ArgumentTypeDescription
arrayArrayThe array to get the last value from

 

Returns:

Any (Any valid data type that an array can hold)

 

Example:

var _last_added_enemy = array_last(enemies);

with (_last_added_enemy)
{
    show_debug_message(string(id) + " is the last enemy in the array.");
}

The above code gets the last enemy instance added to the array enemies and stores it in a temporary variable _last_added_enemy. It then lets that instance display a debug message with the id of the instance.