struct_foreach

This function calls the provided callback function on each member of the struct.

NOTE The member name and value are available in the callback function, but cannot be modified through it.

 

Callback FunctionCallback Function

The callback function to pass into this function should take the following arguments: 

Syntax:

function(member_name, value);

Variable NameData TypeDescription
member_nameStringThe name of the struct member
valueAnyThe value assigned to the struct member

This callback function should not return a value. It simply executes the function on all elements in the given range.

 

Syntax:

struct_foreach(struct, func);

ArgumentTypeDescription
structStructThe struct to use
funcFunction or MethodThe function to execute on each member of the struct

 

Returns:

N/A

 

Example:

var _inventory = {apples: 17, bananas: 261, oranges: 2, lemons: 5};
struct_foreach(_inventory, function(_name, _value)
{
    show_debug_message($"{_name}: {_value}");
});

The above code first creates a temporary variable _inventory that contains a mapping of an inventory item to the number of that item held in the inventory. struct_foreach is then called to display all the amounts using a debug message.