Skip to reading
PCA Script Programming

13. Arrays: lists you can build and edit

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
Code example
function run()
    let clues = ["key", "note"]
    clues = clues + ["watch"]
    clues[1] = "torn_note"
    let count = len(clues)
    return [clues[0], clues[1], count]
end

An array keeps values in order. Its first index is 0 and its last is len(array) - 1. Check the length before reading an index. Do not rely on a missing index returning a useful value.

Code example
function without(values: array, unwanted): array
    let kept = []
    for each value in values
        if value != unwanted
            kept = kept + [value]
        end
    end
    return kept
end
Code example
function run()
    return without(["key", "note", "watch"], "note")
end

There is no general .append(), .remove() or .sort() method API on PCA arrays. Concatenate another array to append; rebuild the list to filter it; use a loop for a search. shuffle() returns a shuffled copy. For a designer-owned array, edit a working value and write the whole array back, rather than assuming that a nested element write will notify the live runtime.

Page 20 of 357Permalink
Go to page