BattleScript Documentation

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, for, and while. 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.

The state keyword is like saying "when in this state, if an event happens, check all the event listeners in this state to see if any match". You define different event handlers inside the state block. Events that occur without a matching state and event keyword will be ignored. If multiple event handlers match an emitted event, they are executed in the order they are defined.

interface Data_IrData {
	int sensorId;
	int playerId;
	int teamId;
	int bulletTypeId;
	int hitValue;
	int isCritical;
}

interface Event {
	string eventName;
}

interface Event_IrrelonFSM_OnEnter extends Event {
	string oldState;
}

interface Event_HardwareIrReceiver_DecodedDataEvent extends Event {
	Data_IrData dynamicIrData;
}

state "inGame" {
	event "irReceiver.decodedData" (Event_HardwareIrReceiver_DecodedDataEvent event) => {
		// Check if we are playing a team-based game
		if (deviceState.gameIsTeamBased.value == true) {
			// Check if the hit came from our own team
			if (event.dynamicIrData.teamId == deviceState.teamId) {
			    // Ignore hits from our own team
				return;
			}
		}

		// Check if bullet is a damage type
		if (event.dynamicIrData.bulletTypeId == bulletTypes.damage) {
			// apply damage: event.dynamicIrData.hitValue;
			return;
		}

		if (event.dynamicIrData.bulletTypeId == bulletTypes.healing) {
			// apply healing: event.dynamicIrData.hitValue;
			return;
		}
	}
}

Getting Help

If you need help with BattleScript, there are several resources available: