Restore [label]
Parameters
| label (optional) - the label to move the Data position to; written .name where it is defined, and without the dot here. Leaving it off rewinds to the very first Data value |
Description
|
Moves the Data position to a label, so the next Read starts from there. When the program starts, the position sits at the first Data value in the source. Restore moves it somewhere else, which is what turns one long Data list into a set of banks you can pick from: Restore level3 For i = 0 To 63 Read tile(i) Next A label marks the point in the Data list where it appears in the source, so put .level3 immediately above the Data lines it belongs to. Give every level, enemy table or dialogue block its own label and you can jump straight to whichever you need, in any order, as often as you like. Restore with no label at all rewinds to the very beginning of the data - handy for restarting a game without reloading anything. Restoring costs nothing and re-reading the same block is perfectly safe, so a Restore just before each read loop is a good habit; it makes the loop work no matter what read from the list last. The labels are the same ones Goto uses, and they follow the same scope rules - a label written in the main program cannot be reached from inside a Function. See also: Data, Read, Goto, Dim. |
Example
; Restore Example ; --------------- ; Restore points the Data pointer at a label, so Data can be ; read in any order - jump straight to level two ... Restore level2 Read name$ Read enemies Print "First we play: "+name$+" ("+enemies+" enemies)" ; ... then move the pointer back to level one Restore level1 Read name$ Read enemies Print "Then we play: "+name$+" ("+enemies+" enemies)" Print "" Print "Press any key to close the example" WaitKey End ; Each level's Data sits under its own label .level1 Data "Grassy Plains",8 .level2 Data "Lava Fortress",15
Index