Getting Started with KrunkScript

KrunkScript is the scripting language for creating custom game modes and experiences in Krunker.

What is KrunkScript?

KrunkScript is a statically-typed scripting language designed specifically for Krunker game development. It provides:

Your First Script

Here's a simple client script that logs a message when the game starts:

# Client Script

public action start() {
    GAME.log("Hello, Krunker!");
}

public action update(num delta) {
    # Game loop runs here
}

Client vs Server Scripts

KrunkScript separates code into two execution contexts:

Client Scripts

Server Scripts

Basic Concepts

Variables

num score = 0;
str playerName = "Guest";
bool isAlive = true;
obj playerData = { x: 0, y: 0 };
num[] scores = num [10, 20, 30];

Functions (Actions)

# Simple function
action sayHello() {
    GAME.log("Hello!");
}

# Function with parameters and return value
num action addNumbers(num a, num b) {
    return a + b;
}

# Public functions are called by hooks
public action start() {
    sayHello();
}

Hooks

Hooks are special public functions that the game calls automatically:

# Called when game starts
public action start() {
    # Initialize your game
}

# Called every frame
public action update(num delta) {
    # Update game state
}

# Called when a player spawns
public action onPlayerSpawn(str id) {
    GAME.log("Player spawned: " + id);
}

Script Types

There are 2 types of scripts in KrunkScript:

Disabling Default Behaviors

Krunker provides a lot of default behavior out of the box. You can disable specific behaviors to customize your game:

GAME.DEFAULT.disablePrediction();        # disable client prediction (client only)
GAME.DEFAULT.disablePlayerBehaviour();   # disable all default player logic (client & server)
player.defaultMovement = false;          # disable movement, jumping & crouching (client & server)
player.defaultVelocity = false;          # disable default velocity (client & server)
player.defaultRotation = false;          # disable default rotations (client & server)
player.disableShooting = true;           # disable shooting & reloading
player.disableMelee = true;              # disable melee
player.disableDefault("jump");           # disable specific default behavior
GAME.DEFAULT.disable3D();                # disable 3D Scene for 2D-only games (client only)
GAME.INPUTS.disableDefault();            # don't send default inputs to server (client only)
GAME.UI.hideDefault();                   # hide most default krunker UI (client only)
GAME.UI.hideCrosshair();                 # hide crosshair (client only)
GAME.PLAYERS.disableMeshes();            # hide default player models

Debugging

Use the following functions to help when debugging:

GAME.log("Text");              # logs text to the browser console
GAME.log(object);              # logs object to console
GAME.log((str) number + "text"); # log number concatenated to string

Next Steps

Guides