Skip to reading
PCA Script Programming

Builtins: Validity and gameplay queries

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
On this page

regex_search()#

Code example
regex_search(pattern, text, all_matches = false)

Search using a regular expression. Escape backslashes for the PCA string before the regex receives it.

Returns: A match dictionary or null; an array of matches when all_matches is true.

Code example
regex_search("(KEY)-(\\d+)", "KEY-204")

A match has text, start, end and groups. groups[0] is the full match. Invalid patterns report a diagnostic and return null/empty. End positions are exclusive.

to_json()#

Code example
to_json(value, indent = "")

Serialize ordinary data to JSON text.

Returns: Text.

Code example
to_json({"open": true, "score": 5}, "  ")

Use arrays, dictionaries, numbers, text, Booleans and null for portable interchange. Vectors, colors and record references are not a general lossless format.

from_json()#

Code example
from_json(text, fallback = null)

Parse JSON text.

Returns: Parsed value; fallback on invalid JSON.

Code example
from_json('{"open":true}', {})

Valid JSON null stays null. This differs from the read_json_file helper’s fallback behavior.

Page 60 of 357Permalink
Go to page