Skip to content

Scripts in the world

Every componentcomponent: One script attached to one entity. The same script on ten entities is ten components, each with its own copy of the script's fields. you’ve seen, transform, model, box_trigger, effect, is a script: a file written in vscript, the language Knockout City’s gameplay is written in. The Inspector’s fields for a component are its script’s settings.

So “writing a script” in Knockout City means making a new kind of component. Put it on an entity, and the game runs it there: when the entity appears, every frame, when something enters a trigger beside it.

A script can reach nearly anything around it: find entities and components, read and change their fields, move things, play effects and sounds, react to triggers, keep score, and send values from the server to every player. The engine offers more than two thousand built-in functions for it.

A script can’t change the engine itself, and it runs as part of a level: it does nothing until an entity with it is spawned.

Before scripting, check whether the game already does it and only needs different values. A lot of behaviour is already a component with settings:

You want Probably
A different match length, team size or ball mix Change gameplay data.
Something that bumps or notices A collider or trigger.
A prop that spins, bobs or plays an animation Maybe a shipped script already does it: search the Project’s scripts first.
Something new to happen when a player does something A script.

Every shipped script can be read in Studio: open it and you see the script as vscript. You can also change one: it becomes an override like any other file, and every component using that script runs your version. To change one component only, write a new script that builds on the shipped one and use it only where you need it.

The vscript section teaches the language from zero, and has a cookbook of common jobs and complete examples.

For programmers

Each script defines a component type. Studio compiles on save, with the same compiler the site’s examples are checked against; shipped scripts open as a decompile. A script’s plain let fields are per-entity settings in the Inspector, let mut fields are runtime state. super "path" inherits from another script, shipped ones included.

Server and client: who runs what.