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

OnExit

From FenixWiki

Revision as of 14:15, 15 December 2007 by Sandman (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Up to Basic Statements



[edit] Definition

Begin
<main code>
[OnExit
<exit code>]
End

The OnExit statement can be used between the Begin and End statements in the Program, Process or Function. When the Program, Process or Function is killed, the exit code starts. This can be easily used to free any memory used by the exiting process.

Available since Fenix 0.90.2.

[edit] Notes

Be advised, Frame statements are interpreted as Frame(0) statements, so the instance will be killed eventually. Code like

Loop frame; End

will cause Fenix to freeze, as frame(0); doesn't allow the program to continue.

[edit] Example

Program example;
Begin // Start the main code part of the main process
    proc1(); // create new instance of proc1
    Loop
        frame;
    End
OnExit // Start the exit code of the main process
End

Process proc1()
Begin // Start the main code part of the process
    Loop
        frame;
    End
OnExit // Start the exit code of the process
End

Function int func1()
Begin // Start the main code part of the function
    return 0;
OnExit // Start the exit code of the function
End

Used in example: loop, end, program, process, function

A good use for this is the following:

Process ship()
Begin
    graph = new_map(20,20,8);
    Loop frame; End
OnExit
    unload_map(0,graph);
End

Used in example: new_map(), unload_map(), graph, loop, frame, end

Personal tools