Scripting

TWIGZ Script Files (".scr"):

All aspects of the TWIGZ engine, whether it be animating non-playable characters (NPCs), starting a conversation, manipulating actor costumes, etc., make use of TWIGZ scripting files. Below is a sample script file followed by a thorough explanation of what scripts are and why they are necessary.

Sample Script File:

5
46
197
349
412
475
1
"Choose Actor",1
"Place Actor",5,99
"Load Costume",1,2,1
"Choose Actor",2
"Place Actor",75,75
"Load Costume",1,1,1
"Set Direction",1,1
"Set ZIndex",1,3
"Set Current Poly",1,2
"Load Script",2

"Fade In"
"End Script"
2
"Change BinVar",1,0
"Add To Inventory",4001
"End Script"
3
"Actor Face Actor",1,2
"Say",2,"But you told me to~stay here so nobody~can come in."
"Say",1,"Well I want you to go~back to my office and~wait for me there."
"Say",2,"You mean lair, right, sir?"
"Say",1,"Yes, yes lair,~that's what I meant."
"Say",2,"You're not the boss,~you're not even on the~same side of the~wall as me."
"Say",1,"So it may seem."
"Say",2,"Listen, you're not~getting in here so~just forget it!"
"End Script"
4
"Load Script",7
"End Script"
5
"IF BV Less",6,50
"Change BinVar",6,0
"IF BV Greater",1,5
"Set TopX",50
"End Script"

Note:
The first number represents the total number of scripts included in this script file. The following 5 numbers represent file offset at which each script starts (these numbers are calculated by the TWIGZ level maker, part of the TWIGZ SDK). Any single number, alone on a line, represents the start of a script. All scripts must end with the "End Script" command.

What are scripts?:
Scripts are what drive the TWIGZ Engine. When a level is loaded (i.e. Level "1.lvl"), the script file of that same number is loaded (i.e. Script "1.scr"). The first script in any script file is the "Enter Script" which is automatically run upon loading the level. This script should be used to set up actor positions and costumes, assign scripts to actors, change and edit Bin Variables, etc.

Scripts run in the background while the engine is running. Currently the TWIGZ Engine supports the simultaneous running of 25 scripts at once (more than you should ever need).

How do they work?:
Scripts are executed line by line. When a new line is read the command is interpreted by the engine and then executed.

How are they triggered?:
Scripts can be triggered in a variety of ways. A script can be triggered after interacting with a "hot-spot", at the beginning or end of a conversation, a script can even be triggered from within another script!

How do animations work?:
Animations are done by way of manipulating an Actor's costume. In order for an animation to run properly the 4 following commands must be used:
1. Choose Actor
2. Set Frames
3. Set Delay
4. Do Animation
5. Stop Animation
The animation will run until the "Loop" parameter of the Do Animation command is finished executing (Note: if this is set to an infinite loop, the animation will not terminate until the level is closed).

How do I create a script?:
There are several, non-complicated steps involved in this process. Before you begin it is recommended that you have a print-out of all the TWIGZ Scripting Commands from the table below.

1. Grab your favorite, simple, MS-DOS text editor (Windows Notepad works fine). If you don't have a favorite you may use edit.exe by loading the TWIGZ Level Editor and clicking on the "Edit Scripts" button.

2. Type the total number of scripts you wish to create followed by an immediate strike of the ENTER key. (NOTE: There CANNOT be any extra spaces at the end of any lines in the script file).

3. Type the script number you wish to work on first.

4. Enter a script command in quotes (Note: these commands ARE case sensitive) followed by a comma (if necessary) and then any appropriate parameters.

5. When you have finished entering all commands, be sure to include the "End Script" command. You may do the same for all other scripts. When you are completely done you can run the TWIGZ Level Editor and click the "Create Script" button to create your script. (Note: make sure all scripts you create are saved in the "SDK\Scripts" folder as ".txt" files).

Top

 

Scripting Commands
Command Parameters Description
     
Dialogue:    
Say ActorID, Text$ The actor says the text
End Dialogue
  This must follow all individual, or sets, of "Say" commands. Can be left out only if the "Say" commands immediately precede an "End Script" command
     
Costumes:    
Choose Actor Actor ID Selects Actor(Actor ID) as the current actor
Place Actor X, Y Places current actor at x, y
Load Costume Costume, Set, Image Sets current actor's current costume, set, and image
Set Frames Costume, Set, Start Image, End Image Sets animation frames by costume & set, then by which images to go through (Increasing or Decreasing order)
Do Animation Loops Loops = [ (-2) - 'Forward & Back Infinite' | (-1) - 'Forward then Back' | (0) - 'Forward Infinite' | (1) - 'Forward Once' ]
Stop Animation   Ends the animation
Set Delay Delay Sets the delay between frames in an animation
Ego Face Actor ActorID Turns Twigz toward the actor
Ego Face Camera   Turns Twigz toward the audience Actor(0)
Actor Face Ego ActorID Turns the actor toward Twigz
Actor Face Actor ActorID1, ActorID2 Turns the first actor toward the second actor
     
Inventory:    
Add To Inventory Inventory ID Adds corresponding Inventory Object to the inventory based on Inventory ID
     
General:    
Load Level Level Number Loads a level
Set TopX TopX Sets the Level.TopX to TopX for scrolling
Change BinVar BinVar Number, Status Changes BinVar Number's status to BinVar Status
BinVar Status BinVar Number Returns the status of that BinVar
Load Script ActorID, Script Number Loads a script to be executed, the executes it (If ActorID = 0, the script is a general level script)
End Script   Ends The Script
Close Script   Close Script File
Close Files   Closes all open files at that current time (used before loading a new level)
Fade In   Fades the screen from black to current palette colors
Fade Out   Fades the screen from current palette colors to black
Ego Animating
Value Pauses all interactivity in game so a scripted animation can run (Value = 0 for FALSE & Value = -1 for TRUE)
Wait Time The script hangs at this point for the duration of Time (Time is a SINGLE floating point number)
     
Enter Script:    
Set Current Poly ActorID, Polygon Sets the Actor's Path.CurrentPoly value to Polygon (currently ActorID is unnecessary because path-finding only works for the Ego)
     
Logic:    
IF BV Equals BinVar, Status IF BinVar = Status THEN execute next line (unless in a BLOCK)
IF BV Less BinVar, Status IF BinVar < Status THEN execute next line (unless in a BLOCK)
IF BV Greater BinVar, Status IF BinVar > Status THEN execute next line (unless in a BLOCK)
IF BV LE BinVar, Status IF BinVar < or = Status THEN execute next line (unless in a BLOCK)
IF BV GE BinVar, Status IF BinVar > or = Status THEN execute next line (unless in a BLOCK)
ELSE   If the ELSE of the previous IF statement is true, execute next line (unless in a BLOCK)
BLOCK   Starts a Logic Block
END BLOCK   Ends a Logic Block
     
BinVar Manipulation:    
INC BV BinVar Increases the value of the BinVar by 1
DEC BV BinVar Decreases the value of the BinVar by 1
     
Walking:    
Actor Walk To ActorID, X, Y Actor walks to point as if the mouse was clicked on (X,Y)
Walk To Object ActorID, ObjectID Actor walks to a certain object by the object's (WalkToX, WalkToY)
Set Direction ActorID, Direction Actor's direction is set to Direction
Set Head Direction ActorID, Head Direction Actor's head is set to Head Direction
Set ZIndex ActorID, ZIndex Actor's z-index is set to ZIndex


The following is a key for the "Parameters" column in the above table:
Key:  
Green
SINGLE floating point number
White
INTEGER

 

 

Top

© 2004 Shattered Realm Productions