Retrieve data about another agent, a list of other agents, or a group agent.
ask(agent-id, expression) ask(group, expression) ask(agent-list, single-valued-expression)
This function returns the value of the given expression, evaluated with respect to the given agent or list of agents. This returns a single value if a single agent is given; or a list of values of the same size if a list of agents is given.
If the first argument is the name of a group, such as
Workplace, then the agent is the group agent representing the calling
agent’s group of that type.
If there is no such agent or the agent is the current agent, this function returns \(0\).
an expression that evaluates to the ID of an agent.
the name of a group.
a list-expression that evaluates to a list of agent ids.
Either a single-valued expression or a list expression.
A single-valued expression (which cannot be a list).
The first two forms return a single value if the second argument is a single-valued expression, and a list of the second argument is a list.
The third form must have a single-valued expression for the second argument. It returns a list with one value per agent listed in the first argument.
The value or values returned are determined by evaluating the second argument with respect to the other agent or agents.
The following sets the value of
sibling_age to the age of the agent whose
ID is stored in the variable
sibling_age = ask(my_sibling, age)
The following sets the value of the list variable
the list of agent IDs stored in the sibling’s personal list variable
sibling_friend_list = ask(my_sibling, my_friend_list)
The following sets
my_household_ages_list to a list of the ages of the
members of the agent’s household:
my_household_ages_list = ask(members(Household), age)
Suppose the calling agent is a member of a group called Theater. Then the
available_tickets to the value of the
personal variable for the group agent of the agent’s Theater:
available_tickets = ask(Theater, my_tickets)