Skip to main content

Script

The file​

  • Every file holds one script; the extension is .kalem, the encoding UTF-8.
  • The script's name is PascalCase and the file's name its kebab-case form: BusinessHours ↔ business-hours.kalem. The compiler checks that they match.
  • The script's id comes from the file name: kalem/business-hours. Components name the script by this id (Components).

The header​

/// Opens and closes the business by its hours and the town's power.
server script BusinessHours extends Building
label "Business · opening hours"
category "Server behaviours"
version 2 // optional, 1 if omitted; used by migration
  • server or client is required: a script runs either in the world or on screen.
  • extends names the script's host type: where it can be attached and what it can use (Host types). The host type must be on the script's side: Building is a server type, VisualEffect a client type.
  • A script extends exactly one host type; scripts do not extend each other.
  • label and category title the script in the Add Component selector and on the component's card. The /// comment above the header is its description.
  • version is 1 when omitted; raising it runs on migrate when a live world moves to the new definition (Saving and migration).

What the side allows​

DeclarationServerClient
property, group, functionyesyes
memory, reads, writes, timeryesno
event handlers, stateyesno
inputnoyes

Server code is never sent to the screen: the compiler puts only client scripts in the client's package.

Several scripts on one object​

A package, a part or the world can take several scripts. Their order is the order of the components in the editor, and it also sets the order of work within a minute.

What a script declares​

After the header, in any order:

DeclarationPage
property, groupProperties
memoryMemory and locals
reads, writesContract fields
on …Events
timerTimers
state, auto stateStates
functionFunctions and expressions
inputClient scripts