static_get

This function returns the Static Struct for the given function or struct.

When you supply a function or method, this function returns the static struct for that function or method.

You can also supply a struct. What's returned depends on the struct: 

NOTE You can pass the result of method_get_index to get the static struct of a method's function.

See: Static Struct

 

Syntax:

static_get(struct_or_func_name);

ArgumentTypeDescription
struct_or_func_nameStructFunction or MethodThe struct, function or method for which to get the static struct

 

Returns:

Struct or undefined (for the root struct)

 

Example 1:

function counter()
{
    static count = 0;
    return count ++;
}

repeat (10) counter()

// Get static struct of counter()
var _static_counter = static_get(counter);

// Both of these read the same variable
show_debug_message(counter.count); // 10
show_debug_message(_static_counter.count); // 10

The above code creates a function counter() with a static variable. The function is called repeatedly so its static variable's value is increased.

The static struct for that function is then returned, and stored in a variable (_static_counter). Then it prints the static variable from the function, by first reading it from the function directly (counter.count) and then reading it from the static struct (_static_counter.count). Both print the same value, as they refer to the exact same variable.

 

Example 2: Going Up in the Static Chain

function item() constructor
{
    static hello = function()
    {
        show_debug_message("Hello World!");
    }
}
function potion() : item() constructor {}

my_potion = new potion();
var _static_potion = static_get(my_potion);
var _static_parent = static_get(_static_potion);
_static_parent.hello();

The above code first creates two constructors: a parent constructor item with a single static function hello and a child constructor potion. It then creates a new potion and stores it in a variable my_potion. Next, a call to static_get is made to get the static struct of my_potion. The returned static struct, stored in a temporary variable _static_potion, is part of the static chain. From this point, all further calls to static_get will move up in the static chain. Another call to static_get is made, which returns the static of item and stores it in another temporary variable _static_parent. Finally, this struct's hello method is called.