Information Technology Reference
In-Depth Information
involves setting (assigning) the value of a given member
(field) in an object:
This is a somewhat complicated construction that you
will see occasionally in recorded script code. The sur-
rounding curly brackets (“ f “and“ g ”) are there to scope
the enclosed script code, so that any new variables that
get created only apply within the scope enclosed by the
brackets. This allows you to reuse the same variable
name without worrying about where else it is used in
the script. The variable that gets created is called ths
(short for “this”), and it is just a shortcut way of re-
ferring to an object. The motivation for doing this is
to allow multiple members of the ths object to be set
without having to repeat the long path name each time.
However, in this case, there is only one member being
set, so it was unnecessary (but the script code generator
was too dumb to figure this out in this case).
There is also a bug in this line of script code (which
is difficult to fix for technical reasons, but can be easily
corrected by editing the script code) — the path name
contains a question mark (?), indicating that it couldn't
quite figure out this part of the path. You might be able
to guess that this should say layers , since we want to
set the layer names here. Thus, you should change these
paths to fit the following example:
.projects[0].networks[0].layers[0].geom \
= "{x=5: y=5: z=1: }";
Here, we are setting the geom member of the first
layer ( layers[0] )tohaveanxvalueof5,ayvalue
of 5, and a z value of 1. This was generated after we re-
sized the layer using the ReSize tool. This line could
have been written more laboriously as the three follow-
ing lines:
.projects[0].networks[0].layers[0].geom.x=5;
.projects[0].networks[0].layers[0].geom.y=5;
.projects[0].networks[0].layers[0].geom.z=1;
where it is clear that x , y ,and z are just members of
the geom object. The shortcut that was actually used
obviously makes for a more compact script.
The next line after this one is a function call to
the UpdateAfterEdit() function, which performs
any updating necessary to take into account any “edit”
changes made by setting new member values. In this
case, it multiplies x times y in the geom ,andcom-
putes the total number of units that will fit within that
geometry, making this the default number of units to
create when the Build() function is later called. You
should see that the script proceeds to set the geometries
for the other layers in the network, and then calls this
Build() function, which is the equivalent of hitting
the Build All button in the network window. After
that, you will see various attempts to resize the hidden
layer ( layers[1] ), and at some point a
{ taNBase* ths = .projects[0].networks[0].\
layers[0];
ths->name = "Input";
}
The next chunk of code deals with the creation of the
projections between the layers, ending with the calling
of the Connect() function. Then you can see where
you created the different layer specifications (which
provides a better example of the use of the scoped ths
variable). Then you can see where the environment was
created, and the PermutedBinary_MinDist func-
tion called (with the same arguments you gave it in the
dialog).
.projects[0].networks[0].layers[1].units.\
RemoveAll();
function call which removed all the units in the layer,
enabling you to subsequently resize it as desired.
B.3.5
Running Processes from the Script
B.3.4
Scoped Variables
Finally we see where the .processes[0] object is
ReInit() and then run. Only the ReInit() func-
tion call shows up, because the others don't make sense
to run in the script. If you were to do:
After the network is built again, you will notice a set of
three lines of the following general form:
{ taNBase* ths = .projects[0].networks[0].?.[0];
ths->name = "Input";
.projects[0].processes[0].Run();
}
Search WWH ::




Custom Search