Skip to main content

Contract fields

A contract field is an object's public value: whether a business is open, whether the town has power, whether Fedai is awake. Fields belong to the object's definition: the fields of a package's or a part's object.json, and of the world's .world document. A script declares the fields it uses:

reads business.open: bool // read only
writes business.visitors: int // read and write

Rules​

  • A field that is not declared can be neither read nor written.
  • A field is used by its name: if business.open, business.visitors += 1.
  • When the script is attached, the field must have the same type in the object's contract (Type mapping); if not, the script does not start.
  • One script writes a field. A second writes of the same field is refused. Any number of scripts may read it.
  • A read sees its own transaction's writes: business.visitors += 1 written twice adds 2.
  • All of a transaction's writes are applied together when it ends; if it fails, none is (Transactions).
  • A write that does not change the value is not a change: it makes no event and no signal.
  • When a field has min/max, a write outside them refuses the transaction.

Defining a field​

Fields are defined in the Inspector's Fields section: key (business.open), label, type (boolean, number, string, time) and default. When a script uses a field the package's contract lacks, Play says so before it starts, and Add the fields they use adds them to the package with the types the script uses.

Fields and signals​

The latest value of a field written on the server reaches the screen as a signal. Client scripts read a field through their input: when the business opens, its sign's neon lights up (Client scripts).