BattleScript Documentation
Getting Started
Learn the basics of BattleScript and set up your environment.
API Reference
Complete reference for all BattleScript functions and methods.
Examples
Sample scripts and code examples for common game modes.
What is BattleScript?
BattleScript is a programming language designed specifically for creating games and control scripts for the BattleCore laser tag system. It allows you to create custom game modes, special effects, and interactive experiences for laser tag players.
With BattleScript, you can:
- Create custom game modes with unique rules and objectives
- Define player interactions and scoring systems
- Control in-game events and triggers
- Customize weapon behavior and feedback
- Create interactive environments that respond to player actions
Basic Syntax
BattleScript has some similarities to JavaScript, Basic and C++, making it easy to learn for those familiar with web development. Here's a simple example of a BattleScript program:
int add (int a, int b = 0) => {
int c = a + b;
return c;
}
int result = add(1, 2);
// This call logs `Result 3` to the console
std::console.log("Result", result);BattleScript supports defining functions, variables, and constants, as well as control statements like if / else, for loops, and evaluatepattern matching. Much like Node.js, BattleScript is executed in an interpreter that has the ability to call functions and access variables that were defined in C++ code in the device binary and operates a similar "native bridge" to the device.
The call to the std::console.log() function is actually a call to a native function registered in the runtime. A full list of native functionality that you can access via BattleScript is available in the API Reference.
Event Driven
BattleScript is unlike other languages in that it has native support for event-driven operations. There are two specific keywords that are used to define event-based functionality: state and event.
Event handlers are organised in three layers: a state contains one or more module blocks, and each module contains the eventhandlers that run while the device is in that state. This says "while in this state, when this module emits this event, run this code". Events that occur without a matching state, module and event are ignored. The handler receives an event object (named evt here by convention) carrying the event details. The "_" wildcard matches any state, module, or event.
state StateEnum.IN_GAME {
module ModuleEnum.IR {
event EventEnum.IN (EventData evt) => {
// Ignore hits from our own team in a team-based game
if (battlecore::game.getIsTeamBased() == true && evt.data.teamId == battlecore::player.getTeamId()) {
return;
}
// Damage bullet type
if (evt.data.bulletTypeId == 0) {
battlecore::player.takeDamage(evt.data.hitValue);
return;
}
// Healing bullet type
if (evt.data.bulletTypeId == 1) {
battlecore::player.takeHealing(evt.data.hitValue);
return;
}
}
}
}Getting Help
If you need help with BattleScript, there are several resources available:
- Browse the Getting Started guide
- Check the API Reference for detailed information on all functions
- Look at Examples to see how to implement common game modes
- Browse community scripts to learn from others