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

Struct

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 23:25, 16 June 2007 (edit)
Sandman (Talk | contribs)

← Previous diff
Current revision (20:53, 26 November 2008) (edit) (undo)
93.125.186.112 (Talk)

 
(One intermediate revision not shown.)
Line 36: Line 36:
</pre> </pre>
Note that the struct [[fileinfo]] is a predefined global variable. Note that the struct [[fileinfo]] is a predefined global variable.
 +
 +This example can also be done by [[Type#Example|defining your own type]].
 +
 +=== Pre-assigning values to a struct ===
 +You can pre-assign values to a single-level struct by putting them after the members, like so:
 +<pre>
 +Struct example
 + Integer X = 100;
 + Integer Y = 50;
 +End;
 +</pre>
 +You can pre-assign values to a struct array by putting them in pairs after the End tag, like so:
 +
 +<pre>
 +Struct Example[3]
 + Integer X;
 + Integer Y;
 +End = 10, 10,
 + 20, 20,
 + 30, 30,
 + 40, 40;

Current revision


Contents

[edit] Definition

STRUCT

Structs are datatypes, able to contain variables of all datatypes.

To address a member of a struct, use the "." operator: <structname>.<membername>. Like all datatypes, one can have a whole range of them, as displayed in the example.

[edit] Example

Structs can be handy for many aspects of programming.

[edit] Multiple identical data groups

Struct Ship[9]
    int x;
    int y;
    int speed;
    int angle;
End

There are 10 'Ship's now. The data can be accessed like:

Ship[0].speed++;
Ship[8].angle = 0;

[edit] Grouping of variables

This is for clarity and to avoid colliding variable names.

Struct Fileinfo
    String name;
    String path;
End

Note that the struct fileinfo is a predefined global variable.

This example can also be done by defining your own type.

[edit] Pre-assigning values to a struct

You can pre-assign values to a single-level struct by putting them after the members, like so:

Struct example
     Integer X = 100;
     Integer Y = 50;
End;

You can pre-assign values to a struct array by putting them in pairs after the End tag, like so:

Struct Example[3]
    Integer X;
    Integer Y;
End = 10, 10,
      20, 20,
      30, 30,
      40, 40;
Personal tools