method_call

This function calls a method with the arguments taken from an array or a range in an array.

If the method needs no arguments then an empty argument array [] can be passed.

NOTE This function works similarly to script_execute_ext but works with methods instead.

 

Syntax:

method_call(method, array_args, [offset], [num_args]);

ArgumentTypeDescription
methodMethodThe method to call
array_argsArrayThe array containing the arguments to pass into the method
offsetRealOPTIONAL The offset, or starting index, in the array. The item at this array index is the first argument for the method. Defaults to 0.
Setting a negative value will count from the end of the array. The starting index will then be array_length(array) + offset. See: Offset And Length
num_argsRealOPTIONAL The number of elements to pass as an argument. A negative value will traverse the array backwards (i.e. in descending order of indices, e.g. 2, 1, 0 instead of 2, 3, 4). See: Offset And Length

 

Returns:

Any (the type returned by the method)

 

Example 1:

struct_with_a_method = 
{
    show_message: function(message)
    {
        show_debug_message("The message is: {0}", message);
    }
}
var _method = struct_with_a_method.show_message;
method_call(_method, ["Hello World!"]);

The above code first defines a struct struct_with_a_method that has a method show_message. The method is then assigned to a temporary variable _method. Next it is called using method_call with an argument array with 1 item in it: the string "Hello World!". The show_message function calls show_debug_message which outputs "The message is: Hello World!".