BattleCore Standard Library
Overview
The BattleCore Standard Library is the set of device functions that BattleScript code uses to control the hardware and game state of a BattleCore device. These functions cover audio, lighting, infrared, networking, the finite state machine, player and weapon state, and more.
Unlike the language standard libraries (std::console, std::debug, std::gpio and std::math), the BattleCore API is not part of the BattleScript language itself. It is provided by the device firmware, and is split into modules that each expose a focused set of native functions.
Namespacing
Every BattleCore function is namespaced under the lowercase battlecore namespace, followed by the module name and the function name:
battlecore::<module>.<fn>(...)
// for example
battlecore::weapon.fire();
battlecore::player.takeDamage(10);
battlecore::fsm.setState(StateEnum.HOME);Including the declarations
Because the BattleCore functions are provided by the firmware rather than the language, their declarations are pulled into your program by include-ing the matching declaration file for the module you want to use:
include "./battlecore/player.bst";
include "./battlecore/weapon.bst";
// the declarations are now available to call
battlecore::player.respawn();The include statement is a textual include of another .bst file. It is how the native declarations and shared enums for each module become visible to your code. This is distinct from the language standard libraries, which are globally available and require no include or import.
Modules
The BattleCore Standard Library is made up of the following modules:
- audio (battlecore::audio) — audio packs, master volume, track and tone playback.
- device (battlecore::device) — device identity, role, mode and volume.
- fsm (battlecore::fsm) — read and set the device finite state machine state.
- game (battlecore::game) — game mode, timing, respawn mode and connection state.
- infrared (battlecore::infrared) — infrared encoding configuration and install/uninstall.
- input (battlecore::input) — create digital inputs bound to GPIO pins.
- lights (battlecore::lights) — control the RGB lights, brightness and effects.
- net (battlecore::net) — network connection state and peer messaging.
- player (battlecore::player) — player life cycle, health, armour, shield and stats.
- screens (battlecore::screens) — current screen and roller navigation.
- storage (battlecore::storage) — persistent key/value storage.
- weapon (battlecore::weapon) — weapon firing, reloading, ammo and shot configuration.
Reference
- Device Events — every event a device emits to your script, and the payload each one carries.