Examples
Short, runnable snippets that show real BattleScript syntax. The standard libraries (std::console, std::math, etc.) are available globally — you do not need to import them.
Hello World and Console
The console functions accept any number of arguments of any type.
std::console.log("Hello, BattleScript!");
std::console.warn("Careful now...");
std::console.error("Something went wrong");See also: std::console
Variables and Constants
Declare typed variables and constants, then use them in expressions.
const int MAX_HEALTH = 100;
int health = 75;
bool isAlive = health > 0;
std::console.log("Health:", health, "/", MAX_HEALTH);
std::console.log("Alive:", isAlive);See also: Variables and Data Types
If / Else If / Else
Control the flow of your program with conditions.
int health = 22;
if (health <= 0) {
std::console.log("Eliminated");
} else if (health < 30) {
std::console.log("Critical");
} else {
std::console.log("Healthy");
}Your Own Functions
Define functions with a return type, parameters and a body, then call them.
int add (int a, int b) => {
return a + b;
}
void greet (string name) => {
std::console.log("Hello, " + name + "!");
}
int sum = add(5, 7);
std::console.log("Sum:", sum);
greet("Player1");See also: Functions
Using the Standard Library
Utility libraries like std::math are namespaced and globally available.
// Random integer between a and b
int roll = std::math.randomInt(1, 6);
// Clamp a value into a range
float volume = std::math.clamp(120.0, 0.0, 100.0);
std::console.log("Rolled:", roll);
std::console.log("Volume:", volume);More: std::math
Arrays and Loops
Declare typed arrays and iterate over them with a for loop. BattleScript has no while loop and arrays currently have no built-in helper methods, so iterate using a known count.
string[] fruits = ["apple", "banana", "cherry"];
for (int i = 0; i < 3; i++) {
std::console.log(i, fruits[i]);
}Enums
Group related named constants together. Members may have string, number or boolean values.
enum BulletType {
DAMAGE = 0,
HEALING = 1,
}
int incoming = BulletType.DAMAGE;
std::console.log("Bullet type:", incoming);See also: Enums
Timers
Schedule code with after (once) and every (repeating). A timer can be stored in a variable so you can stop, start or cancel it.
// Run once after 1 second
after 1000 {
std::console.log("1 second later");
}
// Repeat every 5 seconds, then stop it later
int tickTimer = every 5000 {
std::console.log("tick");
};
stop tickTimer;See also: Timers
States, Modules and Events
Event-driven logic lives inside a state → module → event hierarchy. The handler receives an event object (named evt by convention).
state StateEnum.IN_GAME {
module ModuleEnum.INPUT_TRIGGER {
event EventEnum.DOWN (EventData evt) => {
if (battlecore::weapon.getCanFire()) {
battlecore::weapon.fire();
std::console.log("Firing!");
}
}
}
}See also: Events and States
Where next?
- Jump to Getting Started to install tooling and use the CLI.
- Head to the API Reference for detailed language docs.