Information Technology Reference
In-Depth Information
needed if you were to later compile this using a C++
compiler).
Next, we will define a number of variables which
will parameterize the algorithm for creating the envi-
ronment, including first a pointer to which environment
object to operate on. The backslashes ( n ) in the follow-
ing code indicate that the subsequent line should con-
tinue at the end of the current line — these lines are too
long to be typeset as one line in the topic, but should
appear as one line in the program (without the n ).
Environment* env;
B.5
Writing Script Code to Create an
Environment
One of the most useful applications of the script lan-
guage is for creating environments, often saving con-
siderable time and effort over manually clicking in the
events. We will do a simple example here, which will
contain all the basic elements necessary for doing more
elaborate things. Our objective will be to create events
that have sequentially overlapping patterns (i.e., the first
event has the first 5 units active, the second has 5 units
active starting at unit 3, etc.).
The first thing we need to do is create a home for
the script code that we will write. If the environment
were something that changed dynamically every epoch,
then one would want to associate the script code with
the environment itself (i.e., in a ScriptEnv object),
which has provisions for automatically calling the script
every epoch (or whenever new events are needed). In
the present case, we will just create the environment
once, so that we can do the same thing we did when
we recorded a script — create a Script object in the
.scripts menu.
\
// environment to operate on
int n_events; \
// number of events to create
int in_active; \
// number active in the input layer
int out_active; \
// number active in the output layer
int in_skip; \
// number to skip per event in input
int
out_skip;
\
// and in output layer
Notice that these are defined in three parts, first a type
name (e.g., int for integer), then the name of the param-
eter, and finally a descriptive comment.
Now, we define a set of functions that will accom-
plish the creation of the environment:
Do .scripts/New/Script in the project win-
dow. Use the right mouse button on the new object
Ok button, and then Open anew script_file called
make_env.css . Then Apply on the script edit window,
and then do Edit on the script_file to bring up a
text editor, which we will use to enter the script code.
To write this script, we will create a new object type
in the script language, which will provide a way of orga-
nizing and interacting with the script. We will later edit
an instance of this object type, and obtain an edit dia-
log like those you are accustomed to using, with all the
necessary parameters and functions visible. The script
should begin with the following lines:
void Make(); \
// #BUTTON make the full environment
void MakeEvent(Event* ev, int idx); \
// make one event (number idx)
void MakePattern(Pattern* pat, int idx, \
int active, int skip);
Note that these also have the same basic parts, a re-
turn type (which is void because these functions do not
return anything), a function name (including arguments,
which are defined as a comma-separated list of type-
name pairs), and a descriptive comment. The #BUTTON
after the Make function means that this function will
have a button associated with it in the edit dialog. We
will define the actual code that goes with each of these
functions later, but we need to declare them here first
(so that, for example, other functions can call them).
Finally, we need to declare the class constructor ,
which initializes an instance of this class type whenever
one is created. Thus, we will use this to set the default
values for all the parameters.
class MakeEnv {
// makes environment
public:
This declares the object (class) type name
( MakeEnv ), gives it a little descriptive comment,
and then makes all of what follows publicly accessible
(as opposed to private to the class object itself — this
is not really necessary in the script language, but is
Search WWH ::




Custom Search