Contour scripting language
Bee Script reference
A complete reference for writing games in bee, the object-oriented scripting language used by the Contour engine. Files use the .bee extension and are organized as a flat or nested set of scripts that are compiled together.
1Project Layout & Includes
Scripts live in a tree of .bee files. Use #include to pull in dependencies; paths are relative to the script directory.
// scripts/actor.bee
#include "NPC/Car_p202.bee"
class Actor { ... }
- Each file may declare any number of types (classes, actors, weapons, items, projectiles).
#includeis resolved relative to the including file.- A
globals.bee-style file is a good place to gather shared includes and constants.
2Types
| Type | Purpose | Example |
|---|---|---|
int |
32-bit integer | int health = 100; |
float |
64-bit floating point | float moveSpeed = 12.0; |
bool |
true / false |
bool stayput = false; |
str |
string | str currentWeapon = "Pistol"; |
vec2 |
2D vector | vec2 center = {0.0, 0.0}; |
vec3 |
3D vector | vec3(0.0, 0.0, 0.0); |
vec4 |
4D vector (viewport math) | vec4(0.0, 0.0, 1.0, 1.0); |
obj |
generic handle to an actor, wall, sector, track, etc. | obj sector = getWallSector(); |
Vector construction — two equivalent forms exist:
vec2 a = {1.0, 2.0};
vec3 b = vec3(1.0, 2.0, 3.0);
Vectors support component access and arithmetic:
vec3 p = pos;
p.z -= 150.0;
vec3 particlePos = p + getNormal() * 100.0;
3Declaring Entity Types
Four keywords register placeable / engine-managed types. class declares pure-logic types.
class Actor { ... } // base logic class (not placeable on its own)
actor Cat : Actor { ... } // placeable character
weapon Pistol : Weapon { ... } // placeable weapon
item Croissant : HealthItem { ... } // placeable pickup
projectile Bullet { ... } // placeable projectile
actor,weapon,item, andprojectilecan be instantiated from level data.- Inherit from a base type with
: BaseName. - Override fields in derived types:
actor NPC6 : Friendly {
int health = 100;
float halfWidth = 164;
float halfHeight = 450;
}
Note that actor types implicitly get actor behavior (position, movement, state machines) even without an explicit base:
actor Car_p202 { // no `: Actor`, still fully interactive
event load() { ... }
}
4Fields, Constants & Initialization
Field types are required. Fields may be initialized inline.
class Actor {
float moveSpeed = 12.0;
int health = 100;
str currentWeapon = "Pistol";
bool stayput = false;
vec3 lastTargetPos; // no initializer
int lastTargetId;
}
Constants are declared with const:
const int SECTOR_ACTION_DOOR = 1;
const int PORTAL_TYPE_TOUCH = 1;
const int KEY_SPACE = 37;
const int INPUT_FIRE = 23;
5Functions
Regular functions are called from your own code. Return types are omitted and inferred; parameter types are omitted.
function ifrnd(number) {
return rand(0, 255) < number; // returns bool
}
function switchWeapon(name) {
hideHudLayer("Pistol");
showHudLayer(name);
currentWeapon = name;
}
returnexits the function with a value.- Use
thisinside weapon methods to address the current weapon instance:
event switchTo() {
this.animate(); // getter
this.animate("fire"); // setter
}
6Events
Events are engine callbacks — the engine calls them in response to game activity. Declare them with the event keyword. Parameters are untyped.
Lifecycle & Input (actors)
event load() {
collider(true);
}
event hit(pos, sourceActor, projectile) { ... }
event onInputDown(key) {
switch (key) {
case INPUT_FIRE:
discharge(getCameraPosition(), getDirection());
break;
}
}
event onInputUp(key) { ... }
event onKeyPress(key) { ... }
event onInputAction(action) { ... }
Animation & Timing
event animationDone() { ... } // an animation finished
event walkDone() { ... } // a walk(...) sequence finished
event delayDone() { ... } // a delay() finished
event loopDone() { ... } // an animation loop completed
Sectors, Projectiles, Pickups
// sectors
event trigger(type) { ... }
event enter(actorObj, lastSectorIdx, currentSectorIdx) { ... }
event moveDone() { ... }
// projectiles
event launch() { ... }
event hit(position, surface) { ... }
// pickups / triggers
event enterActor() { ... }
Event Modifiers (before / after / override)
When an event is inherited, you can hook around the base implementation:
// Item.bee
event enterActor() {
if (isVisible()) { hide(); }
}
// WeaponItem.bee — runs BEFORE the base hides the pickup
event enterActor() : before {
if (isVisible()) {
addPlayerAmmo(wpnName, ammo);
}
}
// pRocket.bee — replace the base hide behavior entirely
event animationDone() : override {
// do nothing (own walkDone() controls hiding)
}
: before— runs before the inherited handler.: after— runs after the inherited handler.: override— replaces the inherited handler.
The stateChange() Event
Available inside actor types; receives the previous and current state:
event stateChange() {
if (prevState == "idle" && state == "hit") {
playSound3D("sounds/enemy/pain.ogg", position);
}
}
7State Machines (Machines)
A machine is a finite state machine. Declare it with a default start state, then define state blocks. Each state exposes enter(), exit(), and the same timing callbacks (animationDone, walkDone, delayDone) as entity-level events.
machine crouchState = standing { // starts in "standing"
state standing {
enter() { halfHeight = 336.0; }
exit() { }
}
state crouched {
enter() { halfHeight = 128.0; }
}
}
Transitioning between states is a simple assignment:
thinkState = "attack";
Timing callbacks inside a state only fire while that state is active:
machine thinkState = idle {
state walk {
enter() {
setAnimation("walk");
walk(1.0, 10);
}
walkDone() {
thinkState = "idle"; // advance
}
}
}
State machines can be defined in a base class and extended/overridden in derived types.
8Control Flow & Expressions
if (dist < attackDist) {
thinkState = "attack";
}
else if (health <= 0) {
thinkState = "death";
}
else {
thinkState = "hit";
}
Switch/case (always break):
switch (key) {
case INPUT_JUMP:
velocity.z = 140.0;
break;
case INPUT_CROUCH:
crouchState = "crouched";
break;
}
For loops declare the loop variable with the set keyword (no separate type name needed):
for (set i = wallStart(); i < wallEnd(); i++) {
wall = getSectorWall(i);
wall.tagStopWall();
}
Local variables must be typed before use:
float travel;
int duration;
vec2 center = {0.0, 0.0};
Operators
Arithmetic + - * /, comparison < > == <= >= !=, and compound assignment += -= *=. String concatenation uses +:
print("You picked up " + wpnName);
setHudText("hud", "ammo", bulletInMag + " / " + ammo);
Utility conversions
float x = toFloat(current) / toFloat(total);
selectedMenu = round(mouseSelect);
int d = abs(travel);
9Vectors & Math
vec3 dir = pos - sourceActor.position;
vec3 pushDir = normalize(dir);
pushDir *= 25.0;
push(pushDir);
vec2 n = angleToNormal(angle + 90); // returns vec2
float dist = distance(position, other.position);
10Built-In Properties
Available on actors/items/walls/sectors as appropriate.
| Property | Type | Notes |
|---|---|---|
position |
vec3 |
world position |
velocity |
vec3 |
updated per tick |
acceleration |
vec3 |
per-tick acceleration |
rotation |
— | has .y etc. |
scale |
vec3 |
use setScale(...) |
offset |
vec3 |
local transform offset |
id |
int |
unique id |
health |
int |
|
animation |
str |
current animation name |
type |
str |
type name of another actor |
inputMove |
— | .x, .y movement input |
hitag |
int |
sector/wall tag id |
level |
str |
current/next level (settable) |
11Built-In Functions
Movement & Physics
walk(speed, ticks) // float overload
walk(dir, ticks) // vec2 / vec3 overload
walk(0.0, 0) // stop
aimAt(vec3) aimAway(vec3) aimAwayFromPlayer()
push(vec3) turn(float)
distance(vec3, vec3) normalize(vec3)
delay(int) delayDone()
Collision
collider(bool)
getColliderFlag(int) // COLLIDER_FLAG_TOUCHINGWALL, ONFLOOR, INWATER, etc.
Particles, Materials, Animation
spawnParticle(str name, vec3 pos)
spawnDecal(int id, ...)
setMaterial(int) setScale(vec2/vec3)
setAnimation(str) resetAnimation()
hasAnimation(str) this.animate() / this.animate(str)
isVisible() hide()
Sound & Media
playSound(str) playSound3D(str, vec3)
playMusic(str) playVideo(str)
playShake(int group, str)
playHudAnimation(str layer, str seq)
Actor & Object Queries
getActor(int id) -> obj
getWallSector() -> obj
getSectorWall(int) -> obj
getNearWall() -> obj
getWaypointTrack(int hitag) -> obj
track.clearSelector()
track.setSelectorDir(vec3)
track.addSelector(str, float)
track.getNextWaypointId(vec3, int) -> int
track.getWaypointPosition(int) -> vec3
Sector & Level Geometry
moveSet(int movement, float from, float to)
moveSetDuration(int)
moveStart() moveReverse() isMoving() -> bool
getNextFloor() updateGeometry()
getSurfaceNormal(int) setSurfaceNormal(int, vec2)
getSectorZ(int, vec2) setZ(int, float)
getMorphPoint(int) setMorphPoint(int, vec2)
tagStopWall() tagCutSector(bool)
wallStart() -> int wallEnd() -> int
Sector extent properties: extentsMyFloor, extentsMyCeiling, extentsHighestFloor, extentsLowestFloor, extentsHighestCeiling, extentsLowestCeiling.
Movement constants: SECTOR_MV_CEILINGZ, SECTOR_MV_FLOORZ, SECTOR_MV_ROTATE, SECTOR_MV_MORPH.
HUD
setHudText(str layer, str field, int|str value)
showHudLayer(str) hideHudLayer(str)
showHudSequence(str, str) hideHudSequence(str, str)
showHudFrame(str, str, int) hideHudFrame(str, str, int)
moveHudSequence(str, str, vec2)
Pickups & Player State
useTrigger(float distance)
addPlayerAmmo(str, int)
addPlayerHealth(int, int)
Combat
discharge(vec3 origin, vec3 dir) // on actors
discharge() // on weapons
Game / Map / Menu
loadMap(str level) hideLoadScreen()
isMapLoaded() -> bool hideMenu()
captureMouse() exit()
Utilities
rand(int|int, int|int) rand(float, float)
toFloat(...) round(float) abs(number)
angleToNormal(int) -> vec2
12A Complete Small Example
A pickup item
// scripts/items.bee
class HealthItem : Item {
float pickupRange = 512.0;
int addHealth = 0;
str healthName = "";
event load() {
collider(false);
}
event enterActor() : before {
if (isVisible()) {
str message = "You picked up " + healthName + ".";
if (addHealth > 0) message += "+" + addHealth + " health";
print(message);
addPlayerHealth(addHealth, 0);
}
}
}
item Croissant : HealthItem {
str healthName = "Croissant";
int addHealth = 5;
}
A friendly character
class Friendly : Actor {
str idle_anim = "idle1";
event load() {
idle_anim = "idle" + rand(1, 3);
if (!hasAnimation(idle_anim)) idle_anim = "idle1";
setAnimation(idle_anim);
thinkState = "idle";
}
event hit(pos, sourceActor, projectile) {
if (thinkState != "hit") thinkState = "hit";
}
machine thinkState = idle {
state idle {
enter() { setAnimation(idle_anim); }
}
state hit {
enter() { setAnimation("hurt"); }
animationDone() { thinkState = "idle"; }
}
}
}
A shooting player
actor Player : Actor {
event load() {
collider(true);
movementState = "falling";
switchWeapon("Pistol");
}
event onInputDown(key) {
switch (key) {
case INPUT_FIRE:
showHudSequence(currentWeapon, "fire");
thinkState = "attack";
discharge(getCameraPosition(), getDirection());
break;
case INPUT_JUMP:
movementState = "jumping";
velocity.z = 140.0;
break;
case INPUT_WEAPON_1:
switchWeapon("Pistol");
break;
}
}
machine movementState = falling {
state jumping {
enter() { acceleration.z = 0.0; velocity.z = 140.0; }
}
state falling {
exit() {
if (velocity.z < -200.0) playShake(0, "landing");
}
}
}
}
13Quick-Start Checklist
- Write your types. Extend
Actorfor characters;Weapon,Item,Projectilefor the rest. - Declare fields with types and initializers.
- Hook
event load()to set up collision, animation, and starting state. - Handle input in
onInputDown/onInputUp/onInputAction. - Drive behavior with
machinestate machines and assign states to move between them. - React to timing via
animationDone,walkDone, anddelayDone. - Talk to the engine with the built-in functions (particles, sound, HUD, movement, sectors).
- Include dependencies at the top of each file with
#include "path".
This reference documents the bee language as it appears in the Contour script set. Where the engine provides a value or callback (built-in properties, events, and functions), use the exact identifiers shown.
