breve Documentation: version 1.9 | ||
---|---|---|
<< previous | Chapter 2. "steve" Language Reference | next >> |
Before getting started with the code for a simulation or class, there are often a few special lines at the top of a steve file which begin with an @-character. These lines are called @-directives ("at directives") and they specify information that can help breve to locate classes or other files, or to define some constants that will be used in your simulation. These directives are described below.
@include
and @use
: Load Another Source Filebreve includes a rich hierarchy of classes which are used to construct simulations. To use a class which comes with breve (or another file which you have created yourself), you must tell breve to load in the associated file. You need to load the class before you instantiate it or subclass it.
Classes are loaded using the @include
directive.
It is used simply by specifying the name of the file to include:
@include "Control.tz". |
@use
works the same way, but with a slightly
different syntax, leaving out the quotes and the ".tz" from the file
name:
@use Control. |
@include
and
@use
in terms of how the file is actually loaded.@include
directives are not only used to include
classes which come with the breve distribution, but also potentially classes
that you construct yourself. It is often used in conjunction with the
@path
directive (Section 2.8.2) to specify
the location of classes before loading them.
@path
: Specify a Search Path
The @path
directive specifies a directory that breve
should search in to find files. These directories apply to finding
class files, image files, sound files, archives and any other type of
resource that breve might be looking for. It should go at the top of
the file, before you try to include any other files.
Here's an example of @path
line that searches a
folder in my home directory for class files:
@path "/Users/jk/breve_classes". |
You may specify as many directories with @path
directives as necessary.
@define
: Define a Global Constant
A global constant lets you associate a name with a
constant value in your simulation. The @define
directive
allows you to associate names with ints
,
floats
and strings
.
These constants can be very useful when you have the same value used several
times in a simulation—if you want to change the value, then instead
of making the change several times, you can make it once in the
@define
directive. It can also be useful to assign
meaningful symbols to numbers in your simulation. For example, if your
cellular automata is arbitrarily chosen to be 50x50, then instead of
hardcoding the number 50, it is more flexible and
more descriptive to use a global constant.
Global constants are defined with the following form:
@define constant-name constant-value . |
@define CA_SIZE 50. @define PI_VALUE 3.14159. @define STRING_CONSTANT "Hello". |
+ to print-pi: print "pi is approximately: ", PI_VALUE. |
It is not required, but, by convention, global constants are typically written with all capital letters, to distinguish them from variables.
<< previous | breve Documentation table of contents | next >> |
Program Control Structures | up | Defining Basic Agents |