Variables & Data Types

BambooBasic supports three main data types: integers, floating-point numbers, and strings.



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


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}.



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