Page 1 of 1

What's the best way to read variable length data sections

Posted: Thu Aug 19, 2004 1:53 pm
by GedB
I want to have a variable length list in my data section. Stuff I just want to be able to add to over time without touching my code. You know how it works.

What's the best method? At the moment I am using markers to signify the end of some data, like this:

Code: Select all

Restore RainbowColours

Repeat
  Read Colour.s
  Debug Colour
Until Colour = ""

DataSection
RainbowColours:
Data.s "Red", "Orange", "Yellow", "Green"
Data.s "Blue", "Indigo", "Violet", ""
EndDataSection
It seems clumsy. Anybody have anything better?

Posted: Thu Aug 19, 2004 5:37 pm
by GedB
There's this, which seems nicer.

Code: Select all

Restore RainbowColours

*ColourReader = ?RainbowColours
Repeat
  Debug PeekS(*ColourReader)
  *ColourReader = *ColourReader + MemoryStringLength(*ColourReader) + 1
Until *ColourReader >= ?EndRainbowColours


DataSection
RainbowColours:
Data.s "Red", "Orange", "Yellow", "Green"
Data.s "Blue", "Indigo", "Violet"
EndRainbowColours:
EndDataSection