My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Keywords14  
Keywords(Modeling Guide)
Updated Dec 2, 2011 by benoit.g...@gmail.com



constants

nil

Represents the null value (or undefined value). It is the default value of variables of type agent, point or species when they are not initialized.

true, false

Represent the two possible values of boolean variables or expressions. (see bool).

pseudo-variables

Pseudo-variables are special variables whose value cannot be changed by agents (but can change depending on the context of execution).

self

self is a pseudo-variable (can be read, but not written) that always holds a reference to the executing agent.

  • Example (sets the friend field of another random agent to self and reversely) :
let potential_friend value: one_of (list (species(self)) - self);
if condition: potential_friend != nil {
    set potential_friend.friend value: self;
    set friend value: potential_friend;
}

myself

myself is the same as self, except that it needs to be used instead of self in the definition of remotely-executed code (ask and |create commands). myself represents the sender agent when the code is executed by the target agent.

  • Example (asks the first agent of my species to set its color to my color) :
ask target: first (list (species (self))){
    set color value: myself.color;
}
  • Example (create 10 new agents of my species, share my energy between them, turn them towards me, and make them move 4 times to get closer to me) :
create species: species (self) number: 10 {
   set energy value: myself.energy / 10.0;
   loop times: 4 {
       set heading value: towards (myself);
       do action: move;
   }
}

each

each is a pseudo-variable only used in filter expressions following operators such as where or first_with. It represents, in turn, each of the elements of the target datatype (a list, string, point or matrix, usually).

units

Units can be used to qualify the values of numeric variables. By default, unqualified values are considered as:

  • meters for distances, lengths...
  • seconds for durations
  • cubic meters for volumes
  • kilograms for masses

So, an expression like

let foo type: float value: 1;

will be considered as 1 meter if foo is a distance, or 1 second if it is a duration, or 1 meter/second if it is a speed. If one wants to specify the unit, it can be done very simply by adding the unit name after the numeric value, like:

let foo type: float value: 1 centimeter;

In that case, the numeric value of foo will be automatically translated to 0.01 (meter). It is recommended to always use float as the type of the variables that might be qualified by units (otherwise, for example in the previous case, they might be truncated to 0). Several units names are allowed as qualifiers of numeric variables. As they can be used in expressions directly, they are considered as reserved keywords (and therefore cannot be used for naming variables and species). Their complete list is:

length

meter (default), meters, m, centimeters, centimeter, cm, millimeter, millimeters, mm, decimeter, decimeter, dm, kilometer, kilometers, km, mile, miles, yard, yards, inch, inches, foot, feet, ft.

time

second (default), seconds, sec, s, minute, minutes, mn, hour, hours, h, day, days, d, month, months, year, years, y, millisecond, milliseconds, msec.

mass

kilogram (default),kilogram, kilo, kg, ton, tons, t, gram, grams, g, ounce, ounces, oz, pound, pounds, lb, lbm.

surface

square_meter (default), m2, square_meters, square_mile, square_miles, sqmi, square_foot, square_feet, sqft.

volume

m3 (default), liter, liters, l, centiliter, centiliters, cl, deciliter, deciliters, dl, hectoliter, hectoliters, hl.

These represent the basic metric and US units. Composed and derived units (like velocity, acceleration, special volumes or surfaces) can be obtained by combining these units using the and / operators. For instance:

var one_kmh type: float init: 1 km / h const: true;
var one_microsecond type: float init: 1 sec / 1000;
var one_cubic_inch type: float init: 1 sqin * 1 inch;
... etc ...

Sign in to add a comment
Powered by Google Project Hosting