13. Arrays: lists you can build and edit
function run()
let clues = ["key", "note"]
clues = clues + ["watch"]
clues[1] = "torn_note"
let count = len(clues)
return [clues[0], clues[1], count]
endAn 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.
function without(values: array, unwanted): array
let kept = []
for each value in values
if value != unwanted
kept = kept + [value]
end
end
return kept
endfunction run()
return without(["key", "note", "watch"], "note")
endThere 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.
