Home | SCI Documentation | SCI Tutorials | SCI Tools | SCI Wiki | Community

Chapter 10 - Getting Familiar With Objects

SCI is an object oriented virtual machine. This means that all of your program code is organized in blocks, called objects. Each object serves it's own unique purpose. Some objects are used for the characters in your game, some for windows, some for buttons, some for menus, some for getting input, and so forth.

The objects in your game are made up two types, classes and instances. Classes are the base objects, and instances are the sub-objects, derived from them. Classes are generally only used for creating object bases. Instances are used for objects you'll be working with.

Classes can be created from scratch, or derived from other classes. Instances, however, must be always derived from a class.

Classes can be accessed globally, while instances can only be directly accessed locally (within the same script). To globally access instances, you would have to load it's script, store it's address in a global variable, and reference it from the variable. This will be discussed more later.

Classes and instances consist of two parts, properties and methods , which are explained below.

Understanding The Ego Object

You can think of your game like a movie. The characters in in it, called "Actors", make up the "cast". Each actor has it's own instance (object). The main character in your game, called "Ego", is derived from the Actor class.

Each Actor object contains it's own properties and methods. The properties are it's characteristics. The methods are it's code blocks.

The Ego object has properties defining it's view, loop, cel, among other things. It has methods to accomplish tasks such as positioning it, setting it's direction, and so on.

The Ego instance is pointed to by the global variable "gEgo". To access it's methods and properties, you use the send command.

There are five main ways to access the properties and methods in objects:

Method #1: Setting An Object's Properties

Here's an example of setting the ego's view loop to 2:
(send gEgo:

Method #2: Obtaining An Object's Properties

Obtaining the ego's loop property is basically the same. You simply don't provide any parameter.
(send gEgo:

Method #3: Calling An Object's Methods

Calling a method in an object is very similar as well. As an example, we will call the posn() method in the ego object to set it's position.

The posn() method takes two parameters, the x and the y values to position the ego at.

(send gEgo:
    posn(160 120)

Method #4: Calling An Object's Methods and Obtaining it's Return Value

If a method in an object returns a value, you can obtain it just by calling it. As an example, we will check to see if ego has item #3 in it's inventory. To do this, we call the has() method.

(var hasItem)
hasItem (send gEgo:has(3))

This calls the ego's has() method to check if ego has item #3 in it's inventory. If it does, it will return TRUE, otherwise, it will return FALSE.

Method #5: Accessing Multiple Properties/Methods in an Object

Finally, send methods allow you to set as many properties and call as many methods as you want. To set the ego's view, position it, and then find out if item #3 is in it's inventory, you could do this:


(var hasItem)
  (send gEgo :
    loop( 2)
    posn( 160 120)
    has( 3)

This sets the ego's loop to 2, the position to 160,120, and checks if ego has inventory item #3. If ego has it, hasItem will be TRUE, otherwise, it will be FALSE.

In Conclusion

Info Understanding objects is the trickiest part to learn if you are new to object orientated programming languages. 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.
< Previous: Chapter 9 - Elements of a Script Next: Chapter 11 - Variables >

by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.
Thank you.

© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.