Skip to content

Scripting API

devilExE edited this page Jan 26, 2025 · 9 revisions

Preface

KME v3 brings with it a whole new dimension to making custom maps: custom scripts. You can now script your level, to make it more immersive.
The scripting language used by KME is automataV2, modified for .NET Framework. You can learn more about its syntax at automata.md, with a few exceptions, detailed below.

Differences from automataV2

The $:print function automatically includes a line break (\n), because KME uses Loadson's Log method.
The $:getln function is removed entirely.
Also, a few new variable types (which extend on the object type) are added, but they work the same.
Another thing to keep in mind, is that the file line endings need to be \n specifically (and not window's \r\n)

Unity API

There are a few functions, added along side the default functions, which provide interfacing with Unity.
$:GameObject:Find($!name string) -> Unity's GameObject.Find. Returns GameObject.
$:GameObject:Instantiate($!obj object) -> Unity's Object.Instantiate. object should be a GameObject.
$:GameObject:Destroy($!obj object) -> Unity's Object.Destroy. object should be a GameObject.
$:Vector2($x number, $y number) -> Unity's new Vector2
$:Vector3($x number, $y number, $z number) -> Unity's new Vector3
$:Quaternion($x number, $y number, $z number, $w number) -> Unity's new Quaternion
$:ToEuler($quaternion object) -> Convert from Quaternion to Vector3
$:FromEuler($quaternion object) -> Convert from Vector3 to Quaternion

Karlson specific API

$:LocalPlayer() -> gets PlayerMovement.Instance

Native Objects

As described in the preface, KME extends the object type (called ObjectValue) to NativeValue. Indexing (with the [] operator) into such objects, will access the appropiate field via reflection.
Invoking or accessing native methods is currently not supported.

KME callbacks

Aditionally, KME will call some of your functions, and expect output from them (which is provided via the return keyword).
$onwin() -> called when the player touches the milk. Returning any true value (as per automata) will prevent winning, and let game continue to play.
$onbreak($!collider object, $!other object, $!breakreason number) -> called when a glass object gets destroyed, with the glass instance, the collider instance of what collided and break reason. Returning non-true or non-number value will continue normal execution. Returning a positive value will destroy the object without any other effects. Returning a negative value won't destroy the object at all.

$!breakreason:
0 - Unknown
1 - By Player Collider
2 - By Bullet
3 - From Boomer Explosion (not bullet)

$update($!deltaTime number) -> Unity's Update callback
$fixedupdate($!fixedDeltaTime number) -> Unity's FixedUpdate callback

Note

This wiki is work in progress, many features may be added, reworked or removed entirely.

Clone this wiki locally