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 length of the array will equal to the number of elements in the list of values. Values can be of any type, but this type must match the type of the variable.

If the right-hand side of the assignment is an INCBIN directive, the length of the array will equal to the length of the file and each byte in the file will become one array element. Only byte type arrays can be initialized this way.

Example with value list:

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

Example with INCBIN:

  rem -- load a sprite
  data sprite![] = incbin "sprite.bin"

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.