Variables and Data Types

Overview

BattleScript supports various data types for storing and manipulating values in your scripts. Constants can be declared using the const keyword in front of your variable declaration.

Variable Declaration

Variables in BattleScript are declared by specifying a type then an identifier (name):

string playerName = "Player1";
int health = 100;
bool isActive = true;

Constants

Constants are declared using the const keyword and must be assigned a value at declaration:

const int MAX_HEALTH = 100;
const string GAME_NAME = "Capture the Flag";
const float GRAVITY = 9.81;

Data Types

Primitive and Built-in Types

  • int - Signed integer values (e.g., 42, -7)
  • uint - Unsigned integer values (e.g., 42)
  • float - Floating-point numbers (e.g., 3.14)
  • double - Double-precision floating-point numbers
  • bool - Boolean values (true or false)
  • string - Text strings (e.g., "Hello, world!")
  • null - A value representing no value
  • undefined - An explicitly undefined value
  • any - A special type that can hold any value
  • void - Only used as a function return type

Composite Types

  • array - Ordered collections of values (e.g., [1, 2, 3]). You can also declare typed arrays using bracket syntax, e.g. int[], string[], or Player[].
  • object - Key-value pairs (e.g., { name: "Player1", score: 100 })
  • Custom types defined with interface

Type Conversion

BattleScript does not provide implicit casting syntax. Use appropriate functions from libraries when needed and ensure your variable types match the APIs you call. For example, the standard console functions accept any values.

Related Functions