SCI Studio Tutorial Chapter 11 - Variables: Difference between revisions
Created page with "==Variables== Like any other programming language, SCI contains variables. Variables are areas in memory used to store data which can be manipulated. Variables can be used fo..." |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Variables== | [[Category:SCI Pages]] | ||
[[SCI Tutorials and Guides|SCI Tutorials and Guides Table of Contents]]<br /> | |||
[[SCI Studio Tutorial 1#Table of Contents|SCI Studio Tutorial 1 Table of Contents]] | |||
<div align="center"> | |||
Chapter: | |||
[[SCI Studio Tutorial Chapter 1 - An Introduction To SCI Resources|1]] | | |||
[[SCI Studio Tutorial Chapter 2 - Creating The Game|2]] | | |||
[[SCI Studio Tutorial Chapter 3 - Editing Views|3]] | | |||
[[SCI Studio Tutorial Chapter 4 - Editing Cursors|4]] | | |||
[[SCI Studio Tutorial Chapter 5 - Editing Fonts|5]] | | |||
[[SCI Studio Tutorial Chapter 6 - Editing Pics|6]] | | |||
[[SCI Studio Tutorial Chapter 7 - Editing The Vocabulary|7]] | | |||
[[SCI Studio Tutorial Chapter 8 - An Introduction To Scripts|8]] | | |||
[[SCI Studio Tutorial Chapter 9 - Elements of a Script|9]] | | |||
[[SCI Studio Tutorial Chapter 10 - Getting Familiar With Objects|10]] | | |||
[[SCI Studio Tutorial Chapter 11 - Variables|11]] | | |||
[[SCI Studio Tutorial Chapter 12 - Methods and Procedures|12]] | | |||
[[SCI Studio Tutorial Chapter 13 - Conditional and Looping Statements|13]] | | |||
[[SCI Studio Tutorial Chapter 14 - Making The Title Screen|14]] | | |||
[[SCI Studio Tutorial Chapter 15 - Programming The First Room|15]] | | |||
[[SCI Studio Tutorial Chapter 16 - Handling The Player's "Said" Input|16]] | | |||
[[SCI Studio Tutorial Chapter 17 - Creating and Using Props|17]] | | |||
[[SCI Studio Tutorial Chapter 18 - Handling The Inventory|18]] | | |||
[[SCI Studio Tutorial Chapter 19 - Creating and Using Actors|19]] | | |||
[[SCI Studio Tutorial Chapter 20 - Making An Additional Room|20]] | | |||
[[SCI Studio Tutorial Chapter 21 - Creating and Using Doors|21]] | | |||
[[SCI Studio Tutorial Chapter 22 - Handling The Player's Score|22]] | | |||
[[SCI Studio Tutorial Chapter 23 - Using The Death Handler|23]] | | |||
[[SCI Studio Tutorial Chapter 24 - Using The Print Procedures|24]] | | |||
[[SCI Studio Tutorial Chapter 25 - Customizing The Menubar|25]] | | |||
[[SCI Studio Tutorial Chapter 26 - Game Maintenance|26]] | |||
</div> | |||
<div align="center" style="font-size: 22pt">Chapter 11 - Variables</div> | |||
<br /> | |||
==<br /> Introduction == | |||
Like any other programming language, SCI contains variables. Variables are areas in memory used to store data which can be manipulated. Variables can be used for virtually anything. You can store numbers in them, characters, pointers to objects, strings, said blocks, and more. | Like any other programming language, SCI contains variables. Variables are areas in memory used to store data which can be manipulated. Variables can be used for virtually anything. You can store numbers in them, characters, pointers to objects, strings, said blocks, and more. | ||
Line 158: | Line 193: | ||
That sums up the variables 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. | That sums up the variables 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. | ||
==<br /> References == | |||
<references /> | |||
==<br /> Related Links == | |||
* | |||
| | ||
[[SCI Tutorials and Guides|SCI Tutorials and Guides Table of Contents]]<br /> | |||
[[SCI Studio Tutorial 1#Table of Contents|SCI Studio Tutorial 1 Table of Contents]] | |||
<span style="float: left">[[SCI_Studio_Tutorial_Chapter_10_-_Getting_Familiar_With_Objects|< Previous: Chapter 10 - Getting Familiar With Objects]]</span><span style="float: right">[[SCI_Studio_Tutorial_Chapter_12_-_Methods_and_Procedures|Next: Chapter 12 - Methods and Procedures >]]</span> | <span style="float: left">[[SCI_Studio_Tutorial_Chapter_10_-_Getting_Familiar_With_Objects|< Previous: Chapter 10 - Getting Familiar With Objects]]</span><span style="float: right">[[SCI_Studio_Tutorial_Chapter_12_-_Methods_and_Procedures|Next: Chapter 12 - Methods and Procedures >]]</span> | ||
| | ||
[[Category:Technical Info]] | |||
[[Category:References]] | |||
[[Category:SCI References]] | |||
[[Category:Development]] | |||
[[Category:SCI Development]] | |||
[[Category:Tutorials]] | |||
[[Category:SCI Tutorials]] | |||
[[Category:Guides & Other Help]] | |||
[[Category:SCI Guides & Other Help]] | |||
[[Category:Variables]] | [[Category:Variables]] | ||
Latest revision as of 13:25, 30 March 2025
SCI Tutorials and Guides Table of Contents
SCI Studio Tutorial 1 Table of Contents
Chapter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26
Introduction
Like any other programming language, SCI contains variables. Variables are areas in memory used to store data which can be manipulated. Variables can be used for virtually anything. You can store numbers in them, characters, pointers to objects, strings, said blocks, and more.
There are five different types of variables in SCI games: local , global, parameter, temp and property.
- Local variables are declared in each script. They can be accessed by any of the methods or procedures within the same script.
- Global variables are similar to local variables, except they can be accessed by the methods and procedures of any script. These are infact the local variables of script.000 (main.sc). All of the local variables in main.sc can be accessed by any method or property in any of the 1000 possible scripts.
- Parameter variables are those which are sent to methods and procedures. These will be discussed in detail in Chapter 12.
- Temp variables operate like any other variable, but can only be accessed from within the method or procedure in which they are declared.
- Property variables are declared in each object. They can be accessed one of two ways. They can be accessed from within the object's methods by name, or from other objects and procedures using the send command.
Manipulating Variables
To manipulate variables, you use operators. We'll start with the basic operators: addition (+), subtraction (-), multiplication (*), division (/) and assignment (=).
Assignment
The assignment operator assigns a value to a variable.
Example:= score 100In this example, the variable named "score" is set to contain 100 as it's value.
Addition
The addition operator adds two values
Example:=score (+ 100 20)In this example, the variable named "score" is set to contain 120 as it's value (100 + 20).
Subtraction
The subtraction operator subtracts two values
Example:= score (- 100 20)In this example, the variable named "score" is set to contain 80 as it's value (100 - 20).
Multiplication
The multiplication operator multiplies two values
Example:= score (* 100 20)In this example, the variable named "score" is set to contain 2000 as it's value (100 * 20).
Division
The division operator divides two values
Example:= score (/ 100 20)In this example, the variable named "score" is set to contain 5 as it's value (100 / 20).
Declaring and Using Variables
Local & Global Variables
Local and global variables are set up in the local segment, as discussed briefly in chapter 9. The variables each begin with a name label to create an identifier for them. Following the label, you can optionally specify the array size if it will be used as an array, or the value if you wish to set it to something.
An example of declaring the variables:( local // a variable with no set value, so it will be set to 0 aVariable // A variable set to 30 anotherVariable = 30 // 30 word sized variables (60 bytes total), all set to zero anArray [30] // The six variables in the array are set, the rest will be zero aDeclaredArray [10] = (0 1 2 $ABCD 3 4 ) )
Examples of using the variables:= aVariable 100 Wait(aVariable) = anotherVariable (* aVariable 2) = anArray [ 0] 5 (for (= aVariable 0) (< aVariable 10) (++aVariable ) = anArray [ aVariable ]123 )The use of variables is very straight forward. For more information on the local segment, refer to the <html><a href="javascript:void(0)" onclick="window.open('http://sierrahelp.com/SCI/Definitions/Variables.html', 'Variables','width=750,height=900,scrollbars=yes')">Variables section</a></html> from the SCI Studio Help File.
Parameter Variables
Parameter variables are sent to methods and procedures when called, and can be accessed within them. The variables' labels are defined in the method or procedure's definition.
An example of declaring and using the variables:// two params are defined. The first named aParam, the second named anotherParam. (procedure (aProc aParam anotherParam) FormatPrint ("The first variable is: %d, the second is: %d." aParam anotherParam) )The "aProc" is the name of the procedure. The "aParam" and "anotherParam" are the names of the parameters. This is because the SCI language is derived from the "Lisp" language.
The use of variables is very straight forward. For further information, refer to the <html><a href="javascript:void(0)" onclick="window.open('http://sierrahelp.com/SCI/Definitions/Procedures.html', 'Procedures','width=750,height=750,scrollbars=yes,location=no')">Procedures section</a></html> from the SCI Studio Help File.
Temp Variables
Temp variables are allocated at the beginning of methods and procedures. They operate like any other variable, but are only accessible within the method or procedure which they are declared.
An example of declaring and using the variables:( procedure (aProc ) /* three variables are defined. The first named aVariable is not initialized, the second named anotherVariable is initialized to 30, the last named anArray is an uninitialized 30 variable array.*/ ( var aVariable , anotherVariable= 30, anArray [ 30]) = aVariable 100 Wait(aVariable ) = anotherVariable (* aVariable 2) = anArray [0] 5 (for (= aVariable 0 ) (< aVariable 10 ) (++aVariable) = anArray [aVariable] 123 ) )The use of variables is very straight forward. For more information on the local segment, refer to the <html><a href="javascript:void(0)" onclick="window.open('http://sierrahelp.com/SCI/Definitions/Variables.html', 'Variables','width=750,height=900,scrollbars=yes')">Variables section</a></html> from the SCI Studio Help File.
Property Variables
Property variables are the properties of classes and instances. When accessing them from within their owner object, they operate like any other variable. When accessing them from outside the class, the send operation is used (discussed in the previous chapter).
An example of declaring and using the properties within a class:( class aClass ( properties aProperty 123 anotherProperty 2456 ) ( method (someMethod ) = aProperty 100 Wait(aProperty ) = anotherProperty (* aProperty 2) ) )The use of variables is very straight forward. For further information, refer to the section in the <html><a href="http://sierrahelp.com/SCI/SCIStudio3Help/" target="_blank">SCI Studio help File</a></html>.
That sums up the variables 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.
References
Related Links
SCI Tutorials and Guides Table of Contents
SCI Studio Tutorial 1 Table of Contents
< Previous: Chapter 10 - Getting Familiar With ObjectsNext: Chapter 12 - Methods and Procedures >