Skip to reading
BASIC Scripting

Keep lists and named fields together

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

THE BASIC LANGUAGE

A list answers “which item is second?” A dictionary answers “who owns the list?” BASIC can store one inside the other.

Code example
FUNCTION Run()
    DIM items = ["lamp", "key", "map"]
    DIM card = {"owner": "Ada", "items": items}
    RETURN card.owner & " carries the " & card.items[1]
END FUNCTION

What you should see The function returns Ada carries the key. The sequence is lamp at 0, key at 1 and map at 2.

card.owner reads a named field. card.items[1] reads the items field and then selects its second entry. In a list of length 3, the valid indexes are 0 through 2. Use Len(items) when the list length depends on the game.

When players add their own data#

Use stable field names like owner and items. Keep a displayed sentence, an internal record ID and a numeric index distinct when you pass them to another function. For a potentially empty list, check its length before reading entry 0.

Page 14 of 86Permalink
Go to page