Variables & Data Types

BambooBasic supports three main data types: integers, floating-point numbers, and strings. Two smaller integer types, Byte and Short, save memory in big arrays.



Integer (Int)

Integers are whole numbers without decimal points. They can be positive or negative.

Declaration:

Local age:Int = 25
Local count:Int = 0
Local score:Int = -100


Byte and Short (Small Integers)

Whole numbers in less memory, mostly for big arrays. A Byte takes one byte and holds 0 to 255; a Short takes two bytes and holds -32768 to 32767. A value outside the range wraps round: 300 in a Byte is 44, 40000 in a Short is -25536. Use ToInt to put an element into an Int.

Declaration:

Global fileData:Byte[65536]    ; raw bytes (fileReadBytes, fileWriteBytes)
Global samples:Short[4410]     ; 16-bit sound samples (audQueueStream)
Local value:Int = ToInt(fileData[0])


Double (Floating-Point)

Doubles are numbers with decimal points, used for precise calculations.

Declaration:

Local temperature:Double = 98.6
Local pi:Double = 3.14159
Local speed:Double = -45.5


String

Strings are sequences of characters enclosed in double quotes.

Declaration:

Local name:String = "John"
Local message:String = "Hello, World!"
Local empty:String = ""


String Interpolation

Drop a value straight into a string with a {tag expression} hole – no manual & joining or ToString calls. The tag says what kind of value the hole holds, using the same symbols as a userlib .decls file:

{$expr}     String
{%expr}     Int
{!expr}     Double

The tag is required (there is no untagged form), and those three are the whole set – there is no #/float tag in BambooBasic.

Local name:String = "Bamboo"
Local score:Int = 1250
Local health:Double = 98.5

Print "{$name} has {%score} points and {!health}% health"
Bamboo has 1250 points and 98.500000% health

A hole's body is a normal expression – whatever you could write on the right of an =. In particular a hole may contain:

Print "Double score is {%score * 2}"          ; arithmetic
Print "Player: {$hero\name} ({%hero\hp} HP)"   ; Type / Element field data
Print "Winner: {$podium[0]}"                    ; array element (constant index)
Print "Runner-up: {$podium[place]}"             ; array element (variable index)
Print "Top two: {%highScores[0] + highScores[1]}" ; array elements in an expression

Literal braces: write ~{ and ~} when you want a real brace rather than a hole (just like ~n, ~q and ~t):

Print "A JSON-ish thing: ~{ ~qname~q: ~q{$name}~q ~}"
A JSON-ish thing: { "name": "Bamboo" }

Note: the tag must match the value's type – {%name} when name is a String is a compile-time error that tells you to use {$name}. On the web target, Doubles print JavaScript-style (98.5) rather than the desktop's 98.500000 – the same difference ToString already has between the two targets.



Global vs Local Variables

Local - Variables declared with Local are only accessible within the current function or scope.

Function MyFunction()
    Local x:Int = 10  ; Only accessible in this function
    Print x
EndFunction

Global - Variables declared with Global are accessible from anywhere in the program.

Global playerScore:Int = 0

Function AddPoints(points:Int)
    playerScore = playerScore + points
EndFunction


Type Inference

If you don't specify a type or suffix, BambooBasic infers the type from the assigned value:

Local age = 25          ; Inferred as Int
Local pi = 3.14         ; Inferred as Double
Local name = "John"     ; Inferred as String


Constants

Use Const to declare values that never change:

Const MAX_PLAYERS:Int = 4
Const GAME_TITLE:String = "My Game"
Const PI:Double = 3.14159


Examples

See the Variable Types Example for a complete demonstration.


BambooBasic © 2026 Michael Denathorn