method_call

此函数使用从数组或数组中的范围获取的参数调用 method

如果该方法不需要参数,则可以传递空的参数数组[]

注意 此函数的工作方式类似于 script_execute_ext ,但使用的是方法。

 

语法:

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

参数类型描述
methodMethod要调用的方法
array_argsArray包含要传递到方法中的参数的数组
offsetReal可选 数组中的偏移量或起始索引。此数组索引处的项是该方法的 第一个 参数。 默认为 0。
设置负值将从数组末尾开始计数。然后,起始索引将是 array_length(array)+offset。请参阅:  偏移量和长度
num_argsReal可选 要作为参数传递的元素数。负值将向后遍历数组(即以索引的降序,例如2、1、0而不是2、3、4)。请参阅: 偏移量和长度

 

返回:

Any (the type returned by the method)

 

示例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!"]);

上面的代码首先定义了一个具有方法 show_message 的结构 struct_with_a_method。然后将该方法赋给临时变量 _method。接下来,使用 method_call 其中包含一个包含 1 项的参数数组:字符串 "Hello World!"show_message 函数调用 show_debug_message,它输出"消息是:Hello World!"。