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:
- Client and Server Scripts - Code runs on either the client (player's browser) or server
- Game Hooks - Entry points that respond to game events (spawns, deaths, inputs, etc.)
- Rich API - Access to players, 3D objects, UI elements, networking, and more
- Simple Syntax - Easy to learn, similar to JavaScript and C
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
- Run in the player's browser
- Handle rendering, UI, inputs, and local game state
- Access to
CAMERA,UI,INPUTS,SCENEAPIs - Cannot be trusted for authoritative game logic
Server Scripts
- Run on the game server
- Handle authoritative game state, scoring, and player management
- Access to
ADMIN,NETWORK.broadcastAPIs - Can kick/ban players and manage the game
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:
- client - Handles the core game logic on the client. This runs on the player's browser.
- server - Handles the core game logic on the server. This runs on the game server.
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
- Language Reference - Complete language syntax
- Client Hooks - All client-side hooks
- Server Hooks - All server-side hooks
- API Reference - Full API documentation
- Examples - Complete code examples
Guides
- Game Logic - Players, movement, AIs, inputs, and collisions
- Scene Composition - 3D scene setup, lights, and objects
- Multiplayer & Networking - Client-server communication
- Data Storage - Persistent data and cookies
- Trigger Logic - Non-scripting game logic with triggers
- Resource Packs & Mods - Custom assets, sounds, and CSS