SCI Studio Tutorial Chapter 12 - Methods and Procedures

From SCI Wiki
Revision as of 17:29, 5 August 2013 by Andrew Branscom (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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 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 Procedures section from 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.

 

< Previous: Chapter 11 - VariablesNext: Chapter 13 - Conditional and Looping Statements >