list (type)¶
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 list variable that holds some number of numeric values inside of a variables block.
It is valid for a list to have no elements. Lists are zero-indexed; that is, the first element in a list has an index of 0, the second element has an index of 1, and so on.
Entire lists can be assigned to any expression that returns a list value using:
Individual elements in a list can be assigned using:
When assigning an individual element, if the element index points an element that would be outside of the the bounds of the current list, the list will grow to accommodate it. 0 will be interpolated for the elements at the indices required for expansion.
It is an error to try to get the value of an invalid index in a list. It is an error to use a negative number as an index for a list.
Examples¶
variables {
shared list my_shared_list_1
shared list my_shared_list_2
shared list my_shared_list_3
agent list my_agent_list_1
agent list my_agent_list_2
agent list my_agent_list_3
}
condition DEMO {
start_state = AgentStart
group_start_state = Excluded
meta_start_state = MetaStart
state MetaStart {
my_shared_list_1[0] = 5
print(my_shared_list_1) # Prints 5
print(my_shared_list_1[0]) # Prints 5
print(select(my_shared_list_1, 0)) # Prints 5
my_shared_list_2[2] = 7
print(my_shared_list_2) # Prints 0 0 7
print(my_shared_list_2[0]) # Prints 0
print(my_shared_list_2[1]) # Prints 0
print(select(my_shared_list_2, 2)) # Prints 7
my_shared_list_3 = list(1, 2, 3, 4)
my_shared_list_3[0] = -1
my_shared_list_3[3] = -4
print(my_shared_list_3) # Prints -1 2 3 -4
wait(0)
default(Excluded)
}
state AgentStart {
my_agent_list_1[0] = 5
print(my_agent_list_1) # Prints 5
print(my_agent_list_1[0]) # Prints 5
print(select(my_agent_list_1, 0)) # Prints 5
my_agent_list_2[2] = 7
print(my_agent_list_2, " == 0 0 7") # Prints 0 0 7
print(my_agent_list_2[0]) # Prints 0
print(select(my_agent_list_2, 1)) # Prints 0
print(my_agent_list_2[2]) # Prints 7
my_agent_list_3 = list(1, 2, 3, 4)
my_agent_list_3[0] = -1
my_agent_list_3[3] = -4
print(my_agent_list_3) # Prints -1 2 3 -4
wait(0)
default(Excluded)
}
}