hd2.gif - 9Kb



In fact we’re not limited to processing one object at a time. We can can construct CompoScript files that will act upon a collection of selected objects, or just one object, or just the first loaded, or the most recent, or just those bigger than a given size, or to the right of the canvas, etc.

stairs.gif - 6Kb


The script file “stairs” is an example of a script file that creates a series of objects. Clear the canvas and try dropping the file onto the canvas. This script makes use of a couple of features we have not seen yet. The first of these is a loop of the form


#CompoScript

for loop = 1 to 5

(do various things)

next

(do something else)

end


The “for/next” loop is a fairly familiar construction for anyone used to computer programming. It repeatedly performs the processes in the loop. By default the loop variable (unimaginatively called “loop” in this example!) is incremented by one each time the contents are processed. CompoScript also provides a “step” instruction so we can increment or decrement the loop variable by an amount other than one if we wish.


for loop = 1 to 5

maketext "text<loop>a"
{
 Text: "Step"
 Font: Trinity.Medium
 At: <xpos> <ypos>
 Size: 24
 Angle: 0
 Colour: &FF
 Border: 4 2
}

select last

let xpos = xpos + .width

maketext "text<loop>b"
{
Text: "Up"
 Font: Homerton.Medium
 At: <xpos> <ypos>
 Size: 50 25
 Angle: 0
 Colour: &8800
 Border: 4 2
}

select last

let ypos = ypos + .height

next


You should be able to see from reading the script that each ‘pass’ through the loop will create two text objects, one in Trinity.Medium font and the other in Homerton.Medium. Note the use of the angle brackets in “text<loop>a” and “text<loop>b”. These serve the special function of indicating a variable. If you select the objects on the canvas you will find that the first pass around the loop created text objects called “text1a” and “text1b”, the second pass created “text2a” and “text2b”, etc. The use of the variable provides a way to give each object a distinct name. Strictly speaking this isn’t necessary as Compo is quite happy to have a number of objects with the same name, but it is good practice as it makes it easier to manipulate and distinguish objects from one another.

Now notice that after each text object was created there is a line “select last”. This ensures that the most recently created object is selected. The reason for this is the following line which is used to alter the “xpos” or “xpos” values which are being used to position the bottom left hand corner of each created object on the canvas. The dot variables “.width” and “.height” contain the width and height of the currently selected object. We can use these to ensure that each object is created in an appropriate position even if we alter the sizes of the fonts used or the text. Initial values of “xpos” and “ypos” were set before entering the loop so the location of the first object is defined. Each following object is then placed according to its actual width and height.

Once the loop is completed five pairs of text objects have been created. A final text object is then created before the script is finished.

upstairs.gif - 12Kb


Now drop the script file “shadowup” onto the canvas. You should see each occurrence of the word “Up” gain a soft shadow. The script for this is as follows.


#CompoScript

for loop = 1 to 5

select "text<loop>b"
let .shadow = 1
makemask SHADOW copy BLEND
processmask SHADOW Antialias Smudge AllButBlack
processmask SHADOW Edge Maximum
processmask SHADOW Antialias Smudge All

next

end


Having seen the earlier examples it should now be easy to see that this script simply loops through one set of the objects and applies a shadow to each. In this case the objects are chosen on the basis of their name. It would have been possible to select them in other ways.

stairsw.gif - 10Kb


For example, clear the canvas and drop “stair” onto it again. Now use the mouse to select one object on the canvas. Then drop the script file “shadowidth” onto the canvas. You should find that every object which has the same width as the selected object is given a shadow. The script for this is shown below.


#CompoScript

if .selected > 0 then

let selected_width = .width

select first

for loop = 1 to .objects

if .width = selected_width then

 let .shadow = 1
 makemask SHADOW copy BLEND
 processmask SHADOW Antialias Smudge AllButBlack
 processmask SHADOW Edge Maximum
 processmask SHADOW Antialias Smudge All

endif

select next

next
endif
end


This script also illustrates the use of nested “if” statements. The first one tests to see if any objects are actually selected since the variable “.selected” contains the number of the most recently selected object, or equals -1 if no objects are selected. If an object is selected its width is saved as the value of the variable “selected_width”. The script then starts with the first object and loops through them all in turn. For each object it tests with another “if” statement to see if it shares the same width value as the object that was initially selected. If it does, the object has a process applied to it. The variable “.objects” holds the number of objects on the canvas, so looping from one to this value ensures that all the objects are examined before the loop stops.

stairsel.gif - 14Kb


A particularly useful function for general use is the “doto” instruction. To see this in action clear the canvas and create the stairs again. Now use the mouse to select a few objects and then drop the script “shadowselect” onto the canvas. This time you should see that only the objects you selected are given a shadow. The script for this is shown below.


#CompoScript

doto selection
{
let .shadow = 1
makemask SHADOW copy BLEND
processmask SHADOW Antialias Smudge AllButBlack
processmask SHADOW Edge Maximum
processmask SHADOW Antialias Smudge All
}

end


The command “doto selection” allows us to process just the objects which are currently selected. If we wish, we could also apply “doto "name"” where the name is of a specific object, however it is the ability of the command to apply processes to the selected objects which is particularly useful since it makes it easy to apply effects to whatever set of objects we wish.




prevpage.gif - 1296 bytes homecc2.gif - 8Kb nextpage.gif - 1271 bytes


Content and pages maintained by: Jim Lesurf
using HTMLEdit, Compo, and TechWriter.