Projects, state and actions
A project is a set of definitions. A definition describes a type of Gizmo. A placed instance combines one definition with its own identity and validated state.
Definitions and instances
| Concept | Example | Responsibility |
|---|---|---|
| Project | A collection of game pieces | Atomic installation of up to 16 definitions |
| Definition | my-game.counter, version 1 | Initial state, validator, actions and presentation |
| Instance | One counter at a world cell | Independent saved state and Scape-managed identity |
Types are namespaced identifiers, not display labels. A state version is a positive integer. Types and emojis must be unique within a project. Changing a label is different from changing a type or state version.
Project metadata
Set name and description in the project's defineProject call. They describe the whole project, which may contain several Gizmos. Each definition's label and hint remain separate, short text for the palette and world controls.
| Field | Validation |
|---|---|
name | At most 80 UTF-16 units, with at least one non-whitespace character |
description | At most 1,000 UTF-16 units, with at least 10 units after trimming whitespace |
JavaScript string length uses UTF-16 units, so some emojis count as two. Both fields are required. defineProject and Scape reject missing, partial or invalid metadata. The SDK exports the ProjectMetadata type and validProjectMetadata(value) validator for code that needs to check this shape.
A release captures the metadata with its code. Sell displays that copy; price and creator identity are managed by Scape. Editing local metadata never changes an existing release or approved listing. Create and submit a new release for review to change published copy.
Changing the display name does not change the project's identity; see project identity.
Initial state and validation
initial() creates state for a new placement. valid(value) must verify every field and bound. State must be JSON data: no functions, class instances, non-finite numbers, or circular references.
ts
type State = { count: number };
const valid = (value: unknown): value is State =>
record(value) &&
exactKeys(value, ['count']) &&
Number.isSafeInteger(value.count) &&
Number(value.count) >= 0 && Number(value.count) <= 9999;1
2
3
4
5
6
7
2
3
4
5
6
7
Import record and exactKeys from @scape-wtf/sdk. They help check shape; still check required fields and ranges. The Counter source shows a complete definition.
Actions
An action declares permission and returns new state. Reducers are synchronous and side-effect-free. Use the supplied context for time, actor identity and randomness; do not read the environment or call external services.
ts
increment: {
permission: 'participant',
run: (state, payload) => {
requirePayload(payload, []);
if (state.count >= 9999) {
throw new ObjectActionError(409, 'Reset before adding more.');
}
return { count: state.count + 1 };
},
}1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
requirePayload rejects undeclared keys. It does not validate the types or values of required fields; do that in the reducer. Invalid resulting state is rejected by the runtime.
Permissions
participant: a permitted participant can invoke the action.editor: Scape must grant editing permission for that instance.remover: Scape must grant removal permission for the source.
A disabled button helps the interface but does not enforce authorization. The server checks the action independently. In local tests, you supply context; that does not prove real-world access.
State versus configuration
State belongs to a live instance. Portable configuration copies only declared editor settings for a new placement. It never copies identity, ownership, counters, or topology metadata automatically.
ObjectInstance.linkId is Scape-managed grouping metadata outside authored state. Treat it as opaque. See movement and travel.
ObjectInstance.connections and signalInputs are also Scape-managed metadata. Declare ports and return signals instead of writing these fields. See connectors and signals.
Updates
Live uploads update the entire project atomically in your developer world. Ordinary worlds use fixed releases and update only when you select another release for that world. Existing placed state must validate under the new definitions. There is no automatic state-version migration: remove affected instances before changing identity, state version, fixed collision behavior, or removing a definition.
