- This wiki is out of date, use the continuation of this wiki instead
Type
From FenixWiki
(Difference between revisions)
| Revision as of 22:23, 29 May 2007 (edit) Sandman (Talk | contribs) ← Previous diff |
Revision as of 12:44, 14 November 2007 (edit) (undo) Sandman (Talk | contribs) Next diff → |
||
| Line 1: | Line 1: | ||
| - | + | [[category:language]] | |
| + | [[category:operator]] | ||
| + | |||
| + | == Datatype declaration == | ||
| + | |||
| + | === Definition === | ||
| + | '''Type''' <name> | ||
| + | :<variables> | ||
| + | '''End''' | ||
| + | |||
| + | Creates a new [[datatype]]. It's handled as it it were a [[struct]], so the declared variables are members of the struct. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | Program example; | ||
| + | |||
| + | // Declare the type _point | ||
| + | Type _point | ||
| + | float x; | ||
| + | float y; | ||
| + | End | ||
| + | |||
| + | // Declare the function distance(), because the function returns a datatype | ||
| + | // other than int, so it needs to be declared before usage. | ||
| + | Declare float distance(_point a,_point b) | ||
| + | End | ||
| + | |||
| + | Private | ||
| + | _point p1,p2; | ||
| + | Begin | ||
| + | |||
| + | p1.x = 15.3; | ||
| + | p1.y = 34.9; | ||
| + | p2.x = 165.4; | ||
| + | p2.y = 137.2; | ||
| + | |||
| + | write(0,0,0,0,"Distance: " + distance(p1,p2)); | ||
| + | drw_line(p1,p2); | ||
| + | |||
| + | Repeat | ||
| + | frame; | ||
| + | Until(key(_ESC)) | ||
| + | |||
| + | End | ||
| + | |||
| + | Function float distance(_point a, _point b) | ||
| + | Begin | ||
| + | return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); | ||
| + | End | ||
| + | |||
| + | Function int drw_line(_point a, _point b) | ||
| + | Begin | ||
| + | return draw_line( a.x , a.y , b.x , b.y ); | ||
| + | End | ||
| + | </pre> | ||
| + | Used in example: [[write]](), [[key]](), [[draw_line]]() | ||
| + | |||
| + | == ProcessType == | ||
| + | |||
| + | === Definition === | ||
| + | '''Type''' <processname> | ||
| + | |||
| + | Acquires the [[processTypeID]] of a [[processType]] or [[function]]. This can be useful for example with the functions [[get_id]]() and [[signal]](). | ||
| + | |||
| + | === Example === | ||
| + | <pre> | ||
| + | Program example; | ||
| + | Private | ||
| + | proc proc_id; //int could be used too | ||
| + | Begin | ||
| + | |||
| + | // Start 2 proc's | ||
| + | proc(); | ||
| + | proc(); | ||
| + | proc(); | ||
| + | |||
| + | // Display all alive proc's | ||
| + | y = 0; | ||
| + | while( (proc_id=get_id(type proc)) ) | ||
| + | write(0,0,(y++)*10,0,"proc: " + proc_id); | ||
| + | end | ||
| + | |||
| + | // Wait for key ESC | ||
| + | Repeat | ||
| + | frame; | ||
| + | Until(key(_ESC)) | ||
| + | |||
| + | End | ||
| + | |||
| + | Process proc() | ||
| + | Begin | ||
| + | Loop | ||
| + | frame; | ||
| + | End | ||
| + | End | ||
| + | </pre> | ||
| + | Used in example: [[write]](), [[key]]() | ||
Revision as of 12:44, 14 November 2007
Contents |
Datatype declaration
Definition
Type <name>
- <variables>
End
Creates a new datatype. It's handled as it it were a struct, so the declared variables are members of the struct.
Example
Program example;
// Declare the type _point
Type _point
float x;
float y;
End
// Declare the function distance(), because the function returns a datatype
// other than int, so it needs to be declared before usage.
Declare float distance(_point a,_point b)
End
Private
_point p1,p2;
Begin
p1.x = 15.3;
p1.y = 34.9;
p2.x = 165.4;
p2.y = 137.2;
write(0,0,0,0,"Distance: " + distance(p1,p2));
drw_line(p1,p2);
Repeat
frame;
Until(key(_ESC))
End
Function float distance(_point a, _point b)
Begin
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
End
Function int drw_line(_point a, _point b)
Begin
return draw_line( a.x , a.y , b.x , b.y );
End
Used in example: write(), key(), draw_line()
ProcessType
Definition
Type <processname>
Acquires the processTypeID of a processType or function. This can be useful for example with the functions get_id() and signal().
Example
Program example;
Private
proc proc_id; //int could be used too
Begin
// Start 2 proc's
proc();
proc();
proc();
// Display all alive proc's
y = 0;
while( (proc_id=get_id(type proc)) )
write(0,0,(y++)*10,0,"proc: " + proc_id);
end
// Wait for key ESC
Repeat
frame;
Until(key(_ESC))
End
Process proc()
Begin
Loop
frame;
End
End
