Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

This is an old revision of the document!


DATA

Syntax:

  data varname[] = <value1>, <value2>, <value3>, ...

Or in combination with the INCBIN directive:

  data varname![] = incbin "path/to/binary_file"

The DATA directive allocates a one-dimensional static array in memory filled with pre-initialized data in compile time. The array can be used as a regular array in runtime. Example:

rem ** this will print: 9
data squares[] = 0, 1, 4, 9, 16
print squares[3]

DATA statements can be written anywhere in your program. The following will also work:

print squares[3]
end

rem ** program data **
data squares[] = 0, 1, 4, 9, 16

The data members can be updated in runtime using the LET command:

rem ** this will print 9 first, then -1 **
print squares[3]
let squares[3] = -1
print squares[3]
end
	
rem ** program data **
data squares[] = 0, 1, 4, 9, 16

Again, note there is no runtime array bounds checking. Trying to write data over the array bounds may break the program.