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 01:14, 18 June 2007 (edit)
Sandman (Talk | contribs)

← Previous diff
Current revision (11:35, 27 December 2007) (edit) (undo)
Sandman (Talk | contribs)
m
 
(4 intermediate revisions not shown.)
Line 1: Line 1:
-[[Category:variablecategories]]+[[category:variablecategories]]
 +[[category:general]]
== Definition == == Definition ==
-A public variable is a [[variable]] that is specific to a [[process]] or [[function]] in the same way as a [[private variable]]. However, unlike a private variable, a public variable can be accessed from the rest of the program, by use of the [[ProcessID]].+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. 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]].
== Example == == Example ==
<pre> <pre>
-Process SpaceShip+Program example;
-Public+ 
- int speed;+Declare Process SpaceShip()
- String name;+ 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 Begin
Loop Loop
Line 18: Line 41:
End End
</pre> </pre>
 +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.

Current revision


[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