The bipscript environment is built on top of the squirrel programming language, programming in bipscript can be thought of as programming in squirrel using the bipscript API.
The Squirrel language is an object-oriented programming language used as the scripting language in several video game titles. It was designed to be friendly to real-time applications, this makes it ideal for use in video games and now audio scripting as well.
Primitive types in squirrel include types for boolean values, floating point numbers, integers and strings. Here we declare some primitive types using the local keyword which designates a variable with local scope:
local foo = "I'm a string" local n = 10 local x = 0.125
More complex data structures include arrays and tables. Arrays are a zero-indexed sequence of any type:
local anArray = [2, "string", 3.03] print(anArray[1] + "\n") // prints "string" (plus a newline)
Tables are containers that associate each value with a key:
local bob = {
name = "Bob Johnson",
age = 42,
active = true,
instruments = ["bass", "keyboards"]
}
print(bob.instruments[0] + "\n") // prints "bass"
Basic conditional branching is implemented with an if statement similar to other languages:
local x = 5
if(x > 3) {
print(x + " is greater than 3\n")
}
There are also while loops which work as expected:
local y = 1
while(y <= 10) {
print("y is now " + y + "\n")
y++
}
An alternative to the above is the standard for loop:
for(local z = 1; z <= 10; z++) {
print("z is now " + z + "\n")
}
There is also a foreach loop for arrays and tables:
foreach(key, val in bob) {
print("key '" + key + "' has value: " + val + "\n")
}
local foo = "I'm a string"
local n = 10
local x = 0.125
local anArray = [2, "string", 3.03]
print(anArray[1] + "\n") // prints "string" (plus a newline)
local bob = {
name = "Bob Johnson",
age = 42,
active = true,
instruments = ["bass", "keyboards"]
}
print(bob.instruments[0] + "\n") // prints "bass"
local x = 5
if(x > 3) {
print(x + " is greater than 3\n")
}
local y = 1
while(y <= 10) {
print("y is now " + y + "\n")
y++
}
for(local z = 1; z <= 10; z++) {
print("z is now " + z + "\n")
}
foreach(key, val in bob) {
print("key '" + key + "' has value: " + val + "\n")
}
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.