battlecore::game
The gamemodule exposes game level state: the game id, whether the game is team based, the game clock and time limit, how the game ends, the respawn mode, the connection state, and questions about every player's record. Include its declarations with include "./battlecore/game.bst";.
getGameId
Returns the id of the game this device is in. It is read-only: the host owns its id, and a client takes the host's id when it joins. Use it to ignore mesh events from another game running in radio range.
native int battlecore::game.getGameId ();getIsTeamBased / setIsTeamBased
Gets or sets whether the game is team based.
native bool battlecore::game.getIsTeamBased ();
native void battlecore::game.setIsTeamBased (bool newVal);getTime
Returns how long the game has been in play, in milliseconds. This is the game clock, which every device in the game shares. It is 0 before play begins and after the game ends.
There is no setTime. The game clock belongs to every device in the game, so no one script can move it.
native int battlecore::game.getTime ();getTimeMax / setTimeMax
Gets or sets the game's time limit, in minutes. 0 means no time limit.
native int battlecore::game.getTimeMax ();
native void battlecore::game.setTimeMax (int newVal);end
Ends the game for every device. Use it when the game decides it is over: a flag captured, a hill held. Pass the winning team. Leave it out, or pass 4, when no team won, as in a free-for-all where the standings say who did. Returns false when the device is not playing.
native bool battlecore::game.end (int winningTeamId = 4);A script cannot move the device into GAME_END with battlecore::fsm.setState. Ending the game goes through end, which tells every other device as well.
getLastStandingEnds / setLastStandingEnds
Gets or sets whether the game ends by itself when only one side, or one player, is still in. It is on unless the config says "lastStandingEnds": false. A game that ends itself with end can turn it off.
native bool battlecore::game.getLastStandingEnds ();
native void battlecore::game.setLastStandingEnds (bool ends);getRespawnMode / setRespawnMode
Gets or sets how this game respawns a player. It comes from the config's respawnMode. The firmware gives it no meaning. The shipped games use 0 for "pull the trigger" and anything else for "something else respawns you".
native int battlecore::game.getRespawnMode ();
native void battlecore::game.setRespawnMode (int newVal);getIsConnected / setIsConnected
Returns whether the device is in a game. setIsConnected is declared, but the firmware does not support it: the connection follows the lobby and the mesh.
native bool battlecore::game.getIsConnected ();
native void battlecore::game.setIsConnected (bool newVal);Player records
These answer questions about every player's record values, the 8 slots a game fills with battlecore::player.setRecordValue. Every tagger holds the same records, so every tagger gets the same answer. None of these functions knows what a value means.
native int battlecore::game.getRecordValue (int playerId, int slot);
native int battlecore::game.findPlayerByRecordValue (int slot, int value, int orderSlot = -1, int minOrder = 0, bool highest = false);
native int battlecore::game.getTeamRecordBits (int teamId, int slot);
native int battlecore::game.countPlayersWithRecordValue (int slot, int teamId = 4);
native int battlecore::game.getPlayerSilentMs (int playerId);
native int battlecore::game.getPlayerTeamId (int playerId);
native int battlecore::game.getTeamPoints (int teamId);getRecordValue— returns one of another player's values.findPlayerByRecordValue— returns the player whoseslotholdsvalue, or -1 for nobody. When several match, it picks the lowest value inorderSlot(the highest withhighest), then the lowest player id. Records whoseorderSlotvalue is belowminOrderare skipped, so a script that judged the first answer stale can ask for the next.getTeamRecordBits— returns every value inslotacross a team, ORed together: the team's combined bits.countPlayersWithRecordValue— returns how many players have a value inslotthat is not 0. Pass a team to count one team, or 4 for everyone.getPlayerSilentMs— returns how long since that player's tagger was last heard on the radio, in milliseconds. It is 0 for this tagger. Taggers hear each other at least every ten seconds, so a long silence means the tagger has gone. Each tagger measures its own silence, so two taggers can differ by a few seconds.getPlayerTeamId— returns a player's team as their record says, or 4 when it is not known.getTeamPoints— returns a team's points: the sum of its players' points.
// Slot 0 holds the id of the flag a player carries.
int carrier = battlecore::game.findPlayerByRecordValue(0, 2);
if (carrier != -1) {
std::console.log("Player " + carrier + " has flag 2");
}