11 Scripts |
| You
can extend Anim8or's basic functionality and automate repeated tasks
with scripts written in a
programming
language built into Anim8or. It is designed to make animation easier
with features unique to Anim8or's operation. |
| There
are several places that you can use scripts and they are all written in
the same basic way. However certain aspects are only allowed for
specific kinds of scripts. For example you can't refer to a Figure in
the Object Editor, and the time() function is not
meaningful outside of a Scene. |
Scripts may be used in the following places:
|
| This chapter provides an overview of scripts and the basics
of using them in Anim8or. A more detailed language definition is
provided in the Anim8or Scripting Language Manual. |
Data Types
|
| There
are quite a few predefined types
in scripts. You will recognize some of them but many are specific
to Anim8or. Some common types are: |
| int
- 32 bit signed integer float - single precision floating point number point3 - a vector of 3 floats object - an Object figure - a Figure material - a Material shape - a component of an Object such as a Mesh or Sphere |
Variables
|
| Scripts
use typed variables. You must declare a variable and
give it a type before you can use it. Built-in variables and functions
use normal C rules for their names. That is they must begin with a
letter or an underscore "_" which can be followed by letters,
underscores and digits. Examples are: |
| scale cos AddPoint face2 FIRST_KEY_FRAME _exit |
| User variables begin with a $ character followed by a C name: |
| $counter
$NewIndex $face2
$_first_selected_index |
| Variable declares are like those in C. Variables can
single valus or arrays. You cannot initialize a variable in a
definition however. |
| float $size,
$width; int $i, $counter; shape $mySHape; int $index[10]; /* An array that initially has 10 integers. */ |
| Arrays are much more flexible than those found in most
languages. You can change the number of elements they hold in a running
script, add and delete elements, and do other operations. There is more
about arrays later on in this chapter and in the reference manual. |
Expressions
|
| There
are quite a few predefined types
in scripts. You will recognize some of them but many are specific
to Anim8or. Some common types are: |
| int
- 32 bit signed integer float - single precision floating point number point3 - a vector of 3 floats object - an Object figure - a Figure material - a Material shape - a component of an Object such as a Mesh or Sphere |
Statements
|
| Scripts
support several kinds of run time statements. Many are similar to C but
not all. Statements can be nested to any depth. There are no user
defined functions or goto. |
| The basic statement is an assignment.
It is like C's except you cannot cascade multiple assignments in the
same statement. The value of the expression is computer and saved in
the variable at the left: |
| <variable>
= <expression>; |
| Compound statements
group
several statements together into a single statement. When encountered
each statement within a compound statement is executed in order. They
are useful when you need to use more than one statement as part of a
structured statement. |
| { <statement> <statement> ... <statement> } |
| An if statement allows you to conditionally execute one or more commands. There are two forms one with and else and one without it. The expression is first evaluated. If it is not equal to zero then the <then-statement> is executed. If there is an <else-statement> it is skipped. If the value of the expression is zero then the <else-statement> is executed if one is present. The full statement is: |
| if (
<expression> ) <then-statement> else <else-statement> |
| and the form without an <else-statement> is: |
| if (
<expression> ) <then-statement> |
| A while statement
repeatedly evaluates an expression and executes a statement until the
value of the expression is zero: |
| while (
<expression> ) <statement> |
| A for statement executes it's sub-statement multiple times. For statements are not like those in C. In a script the incriment and limit used with the control variable are computed prior to executing the sub-statement and saved. These values are used each time the body of the for statement has been executed to update the control variable and to test to see if the loop should be executed again. The syntax of a for statement is different from C to help remind you that it does not follow C's rules. There are two forms. The one without the <step-expr> uses a step value of 1: |
| for
<variable> = <init-expr> to <limit-expr> step
<step-expr> do <statement> for <variable> = <init-expr> to <limit-expr> do <statement> |
| The <variable> must be declared prior to the for
statement and must be an int or a float. Initially the
<init-expr> is evaluated and assigned to the <variable>.
Then the <limit-expr> and <step-expr> are evaluated. If
there is no <step-expr> a value of 1 is used. The value of
<init-expr> is compared with that of <limit-expr>. If it is
greater and the value of <step-expr> is greater than zero, or if
it is less than and the value of <step-expr> is negative, or if
the value of <step-expr> is zero then the execution of the for
statement is complete. Otherwise the <statement> is executed, the
saved value of <step-expr> is added to <variable> and they
are tested in the same manner to see if the <statement> should be
executed again. |
| This page was last updated on May
30, 2006 |
Copyright 2006 R. Steven Glanville |