SCI Programming.com
Welcome, Guest. Please login or register.
December 18, 2017, 09:52:33 AM
Home  >  Tutorials  >  Chapter 9: Elements of a Script
Chapter 9: Elements of a Script
About Script Elements

Scripts are made up of what are called segments. There are eleven different segments which you can use in your scripts. They all fit into three different categories: Data, Code and Compiler Directives.

Data Segments
local

The local variables of the script are declared in the local segment. Each variable is 16 bit, meaning it can have a value from -32,768 to 32,767. Variable arrays are also supported.

Code:
(local
    score // no value set, will set later
    maxScore = 100 // value of 100 set
    anArrayOfValues[40] // an array of 40 variables totalling 80 bytes
)

For more information on the local segment, refer to the section in the SCI Studio Help File.

string

The strings in your script can be declared in the string segment. Each string begins with a label identifying it, followed by either the size, a string of text, or both.

Code:
(string     // A simple string.
    SomeString = "This is a string"
    // Numbers can be inserted into the strings.
    AnotherString = ("H" "ELL" "O" $20 "There!" 0)
    // This allocates 40 bytes of an empty string.
    StringBuffer[40]
    // This allocates 20 bytes of string. The first five bytes are filled with "Hello".
    YetAnotherString[20] = "Hello"
)

For more information on the string segment, refer to the section in the SCI Studio Help File.

synonyms

The synonyms in your script can be declared in the synonyms segment. Each synonym consists of two vocab words. This is one of the least used segments, and you will probably never use it in your game.

Code:
(synonyms
    'grab' = 'get'
)

For more information on the synonyms segment, refer to the section in the SCI Studio Help File.

Code Segments
class

SCI, being object orientated, is structured completely around objects. Each class segment defines a class object. Class objects are the most powerful types of objects.

Code:
(class SomeClass of AnotherClass
    (properties
        aProperty 1
        anotherProperty 2
    )
    (method (someMethod aParam anotherParam)
        = aProperty 10
    )
)

Classes are discussed in detail in the next chapter. For even more information on classes, refer to the section in the SCI Studio Help File.

instance

Instances are objects derived from classes. They have slightly more limited functionality, but are very well suited for general purpose objects.

Code:
(instance SomeInstance of SomeClass
    (properties
        aProperty 1
        anotherProperty 2
    )
    (method (someMethod aParam anotherParam)
        = aProperty 10
    )
)

Instances are discussed in detail in the next chapter. For even more information on instances, refer to the section in the SCI Studio Help File .

procedure

Procedures are blocks of code. They operate identical to methods, but are not tied to objects. This being the case, they can be used by any object or other procedure, and accomplish any task.

Code:
(procedure ( someProc aParam anotherParam)
    = aParam 10
)

For more information on procedures, refer to the section in the SCI Studio Help File .

Compiler Directives
script

Every script must have it's script number specified. The script segment tells the compiler which number the current script is (from 0-999). In the following example, it tells the compiler that it's compiling the file script.123.

Code:
(script 123)
define

Define is a very frequently used segment. It allows you to label immediate values. The script header (.sh) files are built of these statements.

Code:
(define A_NUMBER 123)

For more information on defines, refer to the section in the SCI Studio Help File .

include

The include statement tells the compiler to use the specified header with the current script.

Code:
(include "sci.sh")

For more information on the include statement and header files, refer to the section in the SCI Studio Help File .

use

The use statement tells the compiler that the current script uses other script's classes (and in the case of main.sc, variables as well). Each script which is compiled generates a .sco file. The following example means that the script uses the obj.sc script, and reads the obj.sco file.

Code:
(use "obj")

For more information on use statements, refer to the section in the SCI Studio Help File.

preload text

Some scripts use text resource to print all/some of it's text. In this case, it will access the text resource corresponding to the script resource (ie.script.123 would use text.123). If you are contantly accessing the text from text resources, you should use the preload text statement. It loads the text into memory for quicker access.

Code:
(preload text)

That sums up the segments of a script. If you don't fully understand them yet, don't worry. Continue on with the tutorial, doing the step by step examples. When done, you should have a good grasp on them. If you still do not, come back to this chapter and read it again, and look at the links to the help file.

<< Prev Back to Tutorials Next >>

The SCI Programming Community
Copyright © 2007 - 2017, All Rights Reserved.