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

Public variable

From FenixWiki

(Redirected from Public variables)
Jump to: navigation, search


[edit] 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.

To start the declaration of public variables, use Public.

[edit] 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