ask()

Retrieve data about another agent, a list of other agents, or a group agent.

Synopsis

ask(agent-id, expression)
ask(group, expression)
ask(agent-list, single-valued-expression)

Description

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 School or 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\).

Parameters

agent-id

an expression that evaluates to the ID of an agent.

group

the name of a group.

agent-list

a list-expression that evaluates to a list of agent ids.

expression

Either a single-valued expression or a list expression.

single-valued-expression

A single-valued expression (which cannot be a list).

Returns

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.

Examples

The following sets the value of sibling_age to the age of the agent whose ID is stored in the variable my_sibling:

sibling_age = ask(my_sibling, age)

The following sets the value of the list variable sibling_friend_list to the list of agent IDs stored in the sibling’s personal list variable my_friend_list:

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 following sets available_tickets to the value of the my_tickets personal variable for the group agent of the agent’s Theater:

available_tickets = ask(Theater, my_tickets)

See Also

tell()