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..

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.

Discussion

Enter your comment. Wiki syntax is allowed:
R A G F P
 
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies