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.
struct_set_from_hash(struct, hash, val);
Argument | Type | Description |
---|---|---|
struct | Struct | The struct reference to set |
hash | Real | The hash of the variable to set (as returned by variable_get_hash) |
val | Any | The value to assign to the struct variable |
N/A
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.