struct_set_from_hash

This function sets the value of the struct member referred to by the given hash, returned by an earlier call to variable_get_hash.

Accessing a variable through a hash allows for faster access when using a string, compared to using the struct[$ "string"] syntax.

 

Syntax:

struct_set_from_hash(struct, hash, val);

ArgumentTypeDescription
structStructThe struct reference to set
hashRealThe hash of the variable to set (as returned by variable_get_hash)
valAnyThe value to assign to the struct variable

 

Returns:

N/A

 

Example:

point = {x: 200, y: 100};
hash_x = variable_get_hash("x");
repeat(1000)
{
    struct_set_from_hash(data, hash_x, random(room_width));
}

The above code first creates a struct point with an x and y variable in it. Next, the hash for the variable name "x" is then retrieved using variable_get_hash. After that, a repeat loop is executed a total of 1000 times. Every iteration of the repeat loop assigns a new random value to the point's x coordinate. This is done using struct_set_from_hash to optimise this operation.