handle_parse

This function parses a string to create a handle reference.

A handle is represented in a string with this format: "ref <type> <id>".

NOTE You can use string to get the string representation of a handle and real to get the index number that it holds.

 

Syntax:

handle_parse(value_string);

ArgumentTypeDescription
value_stringStringThe string representation of the handle, formatted as "ref <type> <id>"

 

Returns:

Handle (or undefined in case of an invalid string)

 

Example:

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)})");

The code above converts the handle of a sprite named spr_player to its string representation (handle_as_string), and then back into a handle (h). It then outputs each of the created instance variables in a debug message, along with its type. This prints the following:

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

You can see that the original reference is converted into a string, which is then parsed back as a reference, which can again be used in functions just like the original reference.

The values of the handle variables are implicitly converted to their string representation to display them.