This wiki is out of date, use the continuation of this wiki instead

Public variable

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 20:12, 25 July 2007 (edit)
Sandman (Talk | contribs)

← Previous diff
Revision as of 20:59, 21 November 2007 (edit) (undo)
Sandman (Talk | contribs)
m (Example)
Next diff →
Line 40: Line 40:
</pre> </pre>
Used in example: [[say]](), [[key]](), [[Program]], [[Declare]], [[Public]], [[GLobal]], [[Begin]], [[Repeat]], [[Loop]], [[frame]] Used in example: [[say]](), [[key]](), [[Program]], [[Declare]], [[Public]], [[GLobal]], [[Begin]], [[Repeat]], [[Loop]], [[frame]]
 +
This is for example when a ship is needed, of which the speed and name want to be accessible from the rest of the program. This way, one can easily have multiple instances of the same [[ProcessType]], but still have the appropriate variables easily accessible. This is for example when a ship is needed, of which the speed and name want to be accessible from the rest of the program. This way, one can easily have multiple instances of the same [[ProcessType]], but still have the appropriate variables easily accessible.
Notice the use of [[Declare]]. If we wouldn't use it, we could just move the process SpaceShip above the main process. This will have the same result. Notice the use of [[Declare]]. If we wouldn't use it, we could just move the process SpaceShip above the main process. This will have the same result.

Revision as of 20:59, 21 November 2007


Definition

A public variable is a variable that is specific to a process or function in the same way as a private variable. Unlike a private variable, however, a public variable can be accessed from the rest of the program, by use of the ProcessID of that process. This ProcessID must be stored in a variable of type ProcessName. It is like a local variable, but just for one ProcessType instead of for all.

Because of the way the compiler works, public variables are only accessible for processes and functions below the declaration (which in fact is pretty normal). To assist in this matter, the statement Declare was created.

Example

Program example;

Declare Process SpaceShip()
    Public
        int speed = 50;
        String name = "Galactica";
    End
End

Global
    SpaceShip ship;
Begin

    ship = SpaceShip();

    say(ship.name + ": " + ship.speed);

    Repeat
        frame;
    Until(key(_esc))

End

Process SpaceShip()
Begin
    Loop
        frame;
    End
End

Used in example: say(), key(), Program, Declare, Public, GLobal, Begin, Repeat, Loop, frame

This is for example when a ship is needed, of which the speed and name want to be accessible from the rest of the program. This way, one can easily have multiple instances of the same ProcessType, but still have the appropriate variables easily accessible.

Notice the use of Declare. If we wouldn't use it, we could just move the process SpaceShip above the main process. This will have the same result.

Personal tools