Component Parameters
This
section describes how you can parameterize components so that different
instances of the component can have different characteristics.
An Example
The
motivation for this feature is best conveyed by an example. There's a
ready-made Sketchup file provided with the tutorial for you
to look at, called Example2.skp.
You'll notice that the two identical terminals and
their surrounding wall faces are actually two instances of a component
definition. This is a very convenient way of modelling repeated
structures, but sometimes you don't want all the instances to be exactly identical. What if you want the terminals to
display different messages?
There's really only one wall face with a
terminal on it, inside the definition of the component. Consequently,
there's only one place to enter the name of a terminal text file. The
solution is to use a parameter for the terminal filename.
Open up
one of the component instances and take a look at the Wall Properties of the back face. Its permutation is set to $Script, which is a parameter reference to a parameter called Script.
Now close up the component, select one of the instances and look at its Object Properties. You get a window where you can enter parameter definitions. This one has been set up so that the Script parameter has the value Ex2-Term1.txt.
The Script parameter of the other instance has been set to Ex2-Term2.txt.
Try playing the level, and you'll get a different message from each terminal.
Uses of Parameters
There
are many ways that parameters can be used. For example, if you have a
component with a switch in it, you can use a parameter for the tag of
the switch so that different instances of the switch can control
different things. Or if you construct a door as a component, you can
parameterize the tag of the door platform so that different instances
of the door can be opened by different switches.
Groups as well
as component instances can have parameters. This feature is not
strictly necessary, because there can never be more than one instance
of a group. However, you may wish to bring out certain settings of
objects within the group as parameters, so that you can change them
easily without having to open up the group and seek out the objects
concerned.
How it Works
Parameterizable Fields
The following kinds of properties can contain parameter references.
- Tag (of switches, lights, platforms)
- Permutation (of switches, lights, trigger polygons)
- Light (of walls, floors, ceilings)
- Liquid (of polygons)
- Tide control (of liquids)
A parameter reference is a string of the form $name, where name is a parameter name.
Parameter Definitions
Groups and component instances can have parameter definitions, which are set up by selecting the group or instance and choosing Object Properties. Definitions are entered one per line, in the form
name = value
The value in a parameter definition can itself be another parameter reference (i.e. starting with $), in which case it is looked up starting in the next outer group or component instance, as described below.
Parameter Lookup
When
the map is exported, MarathUp traverses all the groups and component
instances in the model and evaluates all the parameter references found
in them. The value of a parameter is found by first looking in the
immediately enclosing group or component instance. If a definition is
not found there, it looks in the next outer group or component
instance, and so forth. If the top level of the model is
reached without finding a definition, an error is reported.
In the next chapter we'll see how to create merged map files.
---