Scripting in MMB, A Guide for the Novice


The following is the first installment of what I hope will prove a useful resource for MMB users without extensive experience in writing script.


I. Variables and Conditional Statements

Variables possess no properties other than a name and a value. The value of a numerical variable is expressed as a number, while the value of a string variable is expressed in alphabetic characters.

In Multimedia Builder's native scripting language, unlike most, all variables have by default the initial value of 0. It is therefore unnecessary to declare variables at the start of the program, unless you wish a variable should at first have some other value.

Arguments in a conditional statement are passed when an expression evaluates to true. That is to say, simply, that conditional statements issue their commands when a condition is met. The condition is generally defined by a certain value or range of values of a variable. A typical conditional statement in MMB will have the following structure:

if (variable=value)
perform these actions
end

The word "end" here ends the statement and is required by MMB.

Conditional statements can be used for a variety of purposes. For instance, say you want the user to be able to click a button and show a graphic, but only if the user has previously started a sound playing. In the script of the object used to start the sound, you would define the value of a variable. Let us call the variable isPlaying, and give it the new value of 1.

isPlaying=1

In the script of the button used to show the graphic, you would then include a conditional statement:

if (isPlaying=1)
Show("graphic")
end

The argument need not require that an exact value be met to perform the actions. Using different (MMB) operators, it is possible extend the condition over a range of values:

If the expression is: Actions will be performed if the current value of v is:
v>0 greater than 0
v<0 less than 0
v<>0 not equal to 0
v>=0 greater than or equal to 0
v<=0 less than or equal to 0
v=0 | v=1 equal to 0 or equal to 1
v>0 & v<>1 greater than 0 and not equal to 1



II. Arrays

Cloning bitmap objects can reduce the word length and thus the memory demands of a project. Indexing such objects for arrays can make script less cumbersome, thus conserving processing power.

Say you have a group of five clones called Clone Group. The clones bear the labels Clone1 - Clone5. Each clone is in a different location on the screen. You wish to simulate animation through a series of hide and show commands. Well, it could be done in the following way. Here is the script for a script object labeled CloneScript:

Hide("Clone Group")
n=n+1
if (n=1)
Show("Clone1")
end
if (n=2)
Show("Clone2")
end
if (n=3)
Show("Clone3")
end
if (n=4)
Show("Clone4")
end
if (n=5)
Show("Clone5")
n=0
Return()
end
ScriptTimer("CloneScript","200")

The script calls itself every 200 milliseconds, adding 1 to the value of n each time. It calls the Return() command when it is finished, to prevent infinite recursion, and just before doing so, resets the value of the variable n, to 0.

As you can imagine, this sort of script would be rather huge if you had fifty clones instead of five. But by indexing the objects in an array - that is, giving the label of each object in the group an identical prefix, followed by a serial number - it becomes possible to use a concise script for any number of objects:

Hide("Clone Group")
n=n+1
Show("Clone[n]")
if (n=5)
n=0
Return()
end
ScriptTimer("CloneScript","200")

Here, with each successive run of the script, the clone object bearing serial number n is shown. The braces [] enclose the name of the variable and instruct the program to append the name of the object with the value of the variable. The same script could be used to display an animation consisting of five hundred clones, simply by replacing the number 5 in the conditional statement with the number 500.

And this does not apply just to clones. Any type of object can be arrayed in this manner to perform any actions.



Visit  The BlissWeb Complex

Close this window or Click Here to return to BlissWarez




©1999 Bliss Products