-
Notifications
You must be signed in to change notification settings - Fork 99
PseudoVariables
The expressions known as pseudo-variables are special read-only variables that are not declared anywhere (at least not in a species), and which represent a value that changes depending on the context of execution.
The pseudo-variable self
always holds a reference to the agent executing the current statement.
- Example (sets the
friend
attribute of another random agent of the same species toself
and conversely):
friend potential_friend <- one_of (species(self) - self);
if potential_friend != nil {
potential_friend.friend <- self;
friend <- potential_friend;
}
The pseudo-variable super
behaves exactly in the same way as self
except when calling an action, in which case it represents an indirection to the parent species. It is mainly used for allowing to call inherited actions within redefined ones. For instance:
species parent {
int add(int a, int b) {
return a + b;
}
}
species child parent: parent {
int add(int a, int b) {
// Calls the action defined in 'parent' with modified arguments
return super.add(a + 20, b + 20);
}
}
myself
plays the same role as self
but in remotely-executed code (ask
, create
, capture
and release
statements), where it represents the calling agent when the code is executed by the remote agent.
- Example (asks the first agent of my species to set its color to my color):
ask first (species (self)){
color <- myself.color;
}
- Example (create 10 new agents of the species of my species, share the energy between them, turn them towards me, and make them move 4 times to get closer to me):
create species (self) number: 10 {
energy <- myself.energy / 10.0;
loop times: 4 {
heading <- towards (myself);
do move;
}
}
each
is available only in the right-hand argument of iterators. It is a pseudo-variable that represents, in turn, each of the elements of the left-hand container. It can then take any type depending on the context.
- Example:
list<string> names <- my_species collect each.name; // each is of type my_species
int max <- max(['aa', 'bbb', 'cccc'] collect length(each)); // each is of type string
- Installation and Launching
- Workspace, Projects and Models
- Editing Models
- Running Experiments
- Running Headless
- Preferences
- Troubleshooting
- Introduction
- Manipulate basic Species
- Global Species
- Defining Advanced Species
- Defining GUI Experiment
- Exploring Models
- Optimizing Model Section
- Multi-Paradigm Modeling
- Manipulate OSM Data
- Diffusion
- Using Database
- Using FIPA ACL
- Using BDI with BEN
- Using Driving Skill
- Manipulate dates
- Manipulate lights
- Using comodel
- Save and restore Simulations
- Using network
- Headless mode
- Using Headless
- Writing Unit Tests
- Ensure model's reproducibility
- Going further with extensions
- Built-in Species
- Built-in Skills
- Built-in Architecture
- Statements
- Data Type
- File Type
- Expressions
- Exhaustive list of GAMA Keywords
- Installing the GIT version
- Developing Extensions
- Introduction to GAMA Java API
- Using GAMA flags
- Creating a release of GAMA
- Documentation generation