handle_parse

此函数解析字符串以创建句柄引用

句柄以字符串形式表示,格式如下:"ref <type> <id>"

注意您可以使用string获取句柄的字符串表示形式,并使用real获取它所保存的索引号。

 

语法:

handle_parse(value_string);

参数类型描述
value_stringString句柄的字符串表示形式,格式为"ref <type> <id>"

 

返回:

Handle (or undefined in case of an invalid string)

 

例子:

sprite = spr_player;
handle_as_string = string(sprite);
h = handle_parse(handle_as_string);

show_debug_message($"{sprite} ({typeof(sprite)})");
show_debug_message($"{handle_as_string} ({typeof(handle_as_string)})");
show_debug_message($"{h} ({typeof(h)})");

上面的代码将名为spr_player的精灵的句柄转换为其字符串表示形式(handle_as_string),然后再转换回句柄(h)。然后,它在调试消息中输出每个创建的实例变量及其类型。这将打印以下内容:

ref sprite 0 (ref)
ref sprite (string)
ref sprite 0 (ref)

您可以看到原始引用被转换为字符串,然后将其解析回作为引用,它可以再次像原始引用一样在函数中使用。

句柄变量的值会隐式转换为其字符串表示形式以显示它们。