Chapter 12: Methods and Procedures

Methods and procedures are code blocks with the functionality of receiving parameters and returning values. They are essential to every SCI game, and used throughout the entire execution of the game.

All code is either in a method or a procedure. Both have the same functionality, but procedures are not tied to objects. Methods are always members of an object.

Methods

Methods give objects functionality and the ability to perform tasks. They can take a virtually unlimited amount of parameters, and have the option of returning a value.

Every object in the template game has methods whether you realize it or not. This is because the base object, "obj", contains a number of them. If a class is derived from another class, it can be called with it's superclass' methods, even if they are not defined in the actual object.

> Example:

> ( method (changeScore addScore) = gScore + gScore addScore (if(> addScore 0 ) (scoreSound:playMaybe()) ) )

> This example is a method called "changeScore" with one parameter, labeled"addScore".

For more information on methods, have a look at the section in the SCI Studio help file .

Procedures

Procedures are just like methods, but are not part of an object. They can take a virtually unlimited amount of parameters, and have the option of returning a value.

Though procedures can be built specifically for use with objects, they generally are not.

> Example:

> (procedure public (IsPosOrNeg aNumber ) (if(< aNumber 0) return( -1) ) return(> aNumber 0) )

> This example is a procedure called "IsPosOrNeg" with one parameter, labeled"aNumber".

For more information on procedures, have a look at the section in the SCI Studio help file .

You should now have a general idea on what methods and procedures are. 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 | Next >>