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

Everything else that doesn't fall into one of the other PB categories.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

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

Post 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?
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post 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 
Post Reply