The classic BASIC way to keep a table of values in your program: level layouts, shop items, enemy waves, tunes. Data lines hold the values, Read takes them into variables one at a time, and Restore chooses where reading starts.
.level1
Data "The Meadow", 8, 4
Data "########", "#..o...#", "#.@..o.#", "########"
Function Main()
Restore level1
Local name:String
Local w:Int, h:Int
Read name, w, h
Print name & " is " & w & " x " & h
Return False
EndFunction
Data is followed by values separated by commas. A value is a number (12,
-3, 1.5, 2.5e3, $FF in hex, %1010 in
binary), True or False, or a string in quotes (~t and the other
~ escapes work as usual). Data holds values, not sums or variable names.
Data lines are never run. When the program is built, every Data item in it goes into one
table, in the order they're written, wherever they are: at the top of the file, inside a
Function, or in an Included file (its Data joins the table where the Include line is).
A long Data line can carry on with _ like any other line.
Read takes the next item into a variable. Several variables can be read at once:
Read name, w, h. A variable can be an Int, Double or String, an array element
(Read prices[i]) or a field (Read enemy\hp).
The item is converted to the variable's type: a number read into a String is the number as
it's written (7 gives "7"), a string read into a number is its value
("12.5" gives 12.5, and text that isn't a number gives 0), and a fraction read into an
Int loses its fraction, as it does in ToInt.
Reading past the last item stops the program with a message that names the Read:
Out of data: Read at Game.bam line 42 has no Data left to read (use Restore to read it again)
A label is a name with a dot in front, on a line of its own. It marks the Data that comes after it. Restore with the label's name, without the dot, makes the next Read start there. Restore on its own goes back to the very first item.
.level1 Data "The Meadow", 8, 4 .level2 Data "The Cave", 10, 5 Restore level2 ; the next Read gives "The Cave" Restore ; back to "The Meadow"
Labels are case-insensitive, and each one can only be used once in a program. A
Restore with a label that doesn't exist stops the build with an error, so a typo can't
send your program off reading the wrong values.
data, read or restore.Data is for values you write out by hand. A table you can work out with sums, such as a sine table, is better made with PreCalc, which fills an array at build time.
See Data.bam (a shop list read into arrays, and levels read in any order with labels), and its web version in examples/Web/11 - Data.
BambooBasic © 2026 Michael Denathorn