Local Variables
A variable is a named location in memory that stores a value. A local variable is a variable that is declared within a function or block and is only accessible within that function or block.
let
Variables declared with let are mutable, which means they can be assigned to after they are declared.
Mutable variables must begin with a lowercase letter.
pub fn Example() {
let x = 123
x = 456
Transmission { "x=" + x } // Outputs: x=456
}
const
Variables declared with const cannot be assigned to after they are declared.
Constant variables may begin with an uppercase or lowercase letter.
pub fn Example() {
const NumBots = 7
NumBots = 8 // Compilation error: Cannot assign to a constant variable
}
use
Context variables get passed into functions automatically
and are declared with the use keyword.
Context variables must begin with a lowercase letter.
pub fn Example() {
use color=#ff8800, density=15 // Context variables
DoSomething("Bob", radius=1.5)
// This is identical to: MakeACharacter("Bob", radius=1.5, color=#ff8800, density=15)
}
// This is a function that takes `name` directly and `radius`, `color` and `density` from context
fn DoSomething(name, [radius, color, density]) {
// ...
}
See the Context section for more information.