.. Classes .. include:: /includes/standard.rst ======================= Classes and instances ======================= SCI games are object oriented. The objects in SCI are called "classes" and "instances". Classes can be created from scratch, or based on other classes. Instances, however, must be derived from a class. You can think of a class as the blueprint for creating a building, and an instance as a building itself. Instances can be created dynamically by calling **new:** on a class, or by explicitly declaring an instance. 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 store it's address in a global variable, and reference it from the variable. Classes and instances have two parts: properties and methods. Properties are 16 bit integers. They work just like other variables, but are attatched to objects. Methods are functions containing code which can be executed by the interpreter. They are declared just like :doc:`procedures`. Of note, explicitly-declared instances can declare new methods on themselves. But they cannot delcare new properties. An instance may only have the properties that were defined on the Class from which it is derived. Though instances cannot add properties, they can change the default values of properties. To access the header of a class or instance, you can use object specific :doc:`keywords `. Class syntax:: (class [of (optional)] (properties ... ) (method ( [ ... &tmp ...]) ) ) Instance syntax:: (instance of (properties ... ) (method ( [ ... &tmp ...]) ) ) Examples:: (class Ego (properties x 0 y 0 view 0 loop 0 cel 0 priority 0 ) (method (draw) (DrawCel view loop cel x y priority) ) (method (setCoords newX newY) (= x newX ) (= y newY) ) ) (class LarryClass of Ego (properties x 0 y 0 view 0 loop 0 cel 0 priority 0 anotherProperty 200 ) (method (getCelWidth) (return (CelWide view loop cel)) ) ) (instance Larry of LarryClass (properties x 80 y 60 view 500 loop 0 cel 0 priority 0 anotherProperty 9900 ) ) (procedure (MyProc &tmp anEvent) ; create a new instance of the Event class dynamically (= anEvent (Event new:)) ; .... do stuff ; delete it (anEvent dispose:) )