GLBasic User Manual

Main sections

12 Advanced

Advanced topics:

This section is designed for experienced programmers and advanced users. You can use a lot of advanced programming techniques in GLBasic.

Local and Global Variables

You can define local variables for subroutines (or the main loop) if you want to keep the subroutine separated from the main code and want to re-use it in another program. You define a local variable within a SUB by using the LOCAL keyword. You can define local numbers, strings and arrays like this:
LOCAL num, word$, num_array[], word_array$[] 

To access a global variable that has the same name as a previously defined local variable use the GLOBAL keyword. See the command-reference of these commands for a sample code.

Dynamic Arrays

GLBasic offers you the ability to re-dim arrays with DIM. If you want to keep the overlapping data use REDIM.
DIM a[5]
DIM a[12][4] // Yes!!

Freeing Memory

Freeing memory used by resources is generally not supported in GLBasic. You can do this very simply though by loading a resource that does not exist in place of the original resource.

This will free the memory that was used to store the image of sprite '0'.

This will free sound number '0'
LOADSOUND "xx", 0, 1 

This will free the memory used for this array.
DIM a[0] 

Hexadecimal Numbers

Hexadecimal numbers can also be used in addition to decimal numbers by prefixing it with '0x'.
ad=127; ah=0xff; 

See also...