Syntax

Writes constant values in a DATASECTION. READ takes them one by one, in order; RESTORE moves the reading position.

DATASECTION
DATA SECTION
  [<label>:]
  DATA[.<type>] <literal>[, <literal>…]
ENDDATASECTION
END DATASECTION
END DATA SECTION
READ[.<type>] <target>
RESTORE [<label>]

Also written : DATASECTION, ENDDATASECTION, READ, RESTORE

Parts

<label>A name followed by : inside the section. RESTORE alone goes back to the first value; RESTORE <label> to the first value after the label. Labels ignore case.
<type>One type per DATA line: none or .i (also .l .q .w .b .a .u .c) for whole numbers, .f or .d for decimals, .s for strings. On READ, it sets the kind to read.
<literal>A literal value: a number (negative, decimal, %1010, 0c12, 0x10, 1.25e2), TRUE or FALSE, or a string in double quotes on a .s line.
<target>Where the value goes: a variable, an array cell (a(1) or a[1]), or a field (p.x).

Good to know

  • Without READ.<type>, the kind comes from the target's sigil: $ reads a string, # a decimal number, no sigil a whole number. Reading a whole number from 2.9 gives 2.
  • DATA is allowed only inside a DATASECTION. The section is not run: put it at the top or at the bottom of the program.
  • DATA 1 + 2, and a string on a line without .s, are compile errors. An unknown RESTORE label is a compile error too.
  • A type mismatch stops the program (BASIC READ type does not match DATA), and so does reading past the last value (BASIC READ reached the end of DATA).
  • READ a, b compiles into a program that does not start. Read one target per READ line.
  • A data label is not a GOSUB label: GOSUB cannot reach it. AGK has no DATA; aukimi follows PureBasic's typed DataSection.

Example

RESTORE LevelsREAD countFOR i = 1 TO count  READ name$  READ.f speed#  Console(name$ + " " + Str(speed#))   ' Forest 1.5, then Cave 2.25NEXTRESTOREREAD firstConsole(Str(first))   ' 99DATASECTION  DATA 99  Levels:  DATA 2  DATA.s "Forest"  DATA.f 1.5  DATA.s "Cave"  DATA.f 2.25ENDDATASECTION
In the manual : Arrays, lists and maps

See also