GLBasic User Manual

Main sections

TYPE

TYPE name
members
ENDTYPE



The TYPE command is used to create a data structure. A detailed description can be found in the tutorials.
In order to create a variable of type 'name' you would do the following:
LOCAL variable AS name
GLOBAL variable AS name


Example:
TYPE CAR
company$
costs
ENDTYPE

LOCAL Audi AS CAR

Audi.company$ = "Audi AG, Ingolstadt"
Audi.costs = 40000




You can also have an array of TYPEs
TYPE TWorker
Name$
Annual_Wage
ENDTYPE

GLOBAL Employees[] AS TWorker
DIM Employees[5]

You can easily make that a multi-dimensional array by
GLOBAL Employees[] AS TWorker
DIM Employees[5][4]


If you have an array of TYPEs, you can remove items with DIMDEL and DELETE or DIMPUSH new elements to the back of the array.

If you want to loop through each element in an array of TYPEs, use the FOREACH command.

The last value of an array is either a[LEN(a[])-1], or simply a[-1].

See also...