SCI Programming.com
Welcome, Guest. Please login or register.
June 29, 2017, 06:43:08 AM
Home  >  Tutorials  >  Chapter 12: Methods and Procedures
Chapter 12: Methods and Procedures
About Variables

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.

Code:
( 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.

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

Examples of using the variables:

Code:
= aVariable 100
Wait(aVariable )
= anotherVariable (* aVariable 2 )
= anArray[ 0] 5
(for (= aVariable 0) (< aVariable 10) (++aVariable )
  = anArray[ aVariable] 123
)

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 Back to Tutorials Next >>

The SCI Programming Community
Copyright © 2007 - 2017, All Rights Reserved.