Directives

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 File

breve 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.

There is no different between @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 (the section called “path: Specify a Search Path”) 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-nameconstant-value .

Here are some examples:

@define CA_SIZE                 50.
@define PI_VALUE                3.14159.
@define STRING_CONSTANT         "Hello".

By setting these constants at the top of the source file, you can use them later on. For example:

+ 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.