table¶
Syntax¶
Parameters¶
<scope>-
The scope of the variable being declared. Valid values for scope are
sharedandagent.Important
For
agent-scoped variables,tableandlist_tablevariable types are currently disabled, as they would be extremely memory-intensive with fairly ordinary numbers of agents.
<variable_name>- A name to give the newly declared variable. If multiple are present, they must be separated by a space. Variable names must start with a letter and contain no symbols.
Description¶
Declares a table variable inside of a variables block.
Each key is paired with a single value. Both keys and values are real numbers.
Values in tables can be set and retrieved using the square brackets like so:
# Let's use 1 as the key
my_table_variable[1] = 999
my_variable = my_table_variable[1]
# Let's use list(1,2) as the compound key
my_table_variable[list(1,2)] = 50
my_variable = my_table_variable[list(1,2)]
# Now my_variable is 50
When looking up values in a table, an error occurs if the key does not exist,
unless the table has called set_default_value,
in which case the default value is returned as the value of the lookup.
Examples¶
The following declares a table variable called lookup_table1.