BSL Basics

Now that you have BSL installed, it is time to learn the foundational building blocks of the language. If you have ever written JavaScript or C, you will find BSL incredibly familiar.

BSL Syntax

Syntax refers to the set of rules that defines how a BSL program is written.

Semicolons
In BSL, statements are separated by semicolons (;). While some languages make this optional, it is a standard practice in BSL to end every executable statement with a semicolon to ensure the interpreter reads your code exactly as intended.

// Try it Yourself:
var x = 5;
var y = 10;
print(x + y);

Comments
Comments are used to explain code and make it more readable. The BSL interpreter completely ignores comments when running the script.

Single-line comments start with two forward slashes //.
Multi-line comments start with /* and end with */.

// Try it Yourself:
// This is a single-line comment
print("Learning BSL!"); // This comment is at the end of a line

/*
This is a multi-line comment.
It can span multiple lines.
Great for writing long explanations!
*/

BSL Output

Before we learn how to store data, we need to know how to display it!
To output data or text to the host console (your terminal or command prompt), BSL uses the built-in print() function.

// Try it Yourself:
print("Hello World!");
print(100);

Whenever you run a script, anything inside the print() function will be printed to the screen.

BSL Input

To make your scripts interactive, you can ask the user to provide data while the script is running using the built-in input() function.

When the interpreter reaches the input() function, it prints your prompt to the terminal, pauses the script, and waits for the user to type something and press Enter.

// Try it Yourself:
var x = input("Enter Number: ");

print("You entered: " + x);

The String Caveat
It is very important to remember that the input() function always returns a String, even if the user types a number!

BSL Variables

Variables are containers for storing data values. In BSL, you create a variable using the var keyword.

Dynamic Typing
BSL is a dynamically typed language. This means you do not have to tell BSL what type of data the variable will hold (like text or numbers). Furthermore, a variable can hold a number right now, and later be updated to hold a string!

// Try it Yourself:

// Creating variables
var playerName = "Alice";
var score = 100;

print(playerName);
print(score);

// Reassigning to a different data type (Dynamic Typing)
score = "One Hundred";
print("Updated score: " + score);

BSL Data Types

While you don't explicitly declare types, BSL works with several standard data types under the hood. The most common ones you will use are Numbers and Strings.

Numbers (Integers and Floats)
BSL handles all numeric operations using double-precision floating-point numbers. This means it smoothly handles both whole numbers and decimals.

Integers: Whole numbers (e.g., 10, 42, -5).
Floats: Numbers with a decimal point (e.g., 3.14, 0.99).

// Try it Yourself:
var price = 19.99;  // Float
var quantity = 3;   // Integer

var total = price * quantity;
print("Total cost: " + total);

Strings
Strings are text. They must be wrapped in double quotes "".

// Try it Yourself:
var greeting = "Welcome to BSL!";
print(greeting);

The Concatenation Quirk (Math vs. Glue)
Because BSL uses the + operator for both mathematical addition and string concatenation (gluing text together), you need to be careful when mixing numbers and strings!

Number + Number = Math
String + Number = String (The number is converted to text and glued to the string)

// Try it Yourself:

// Pure Math
print(123 + 123); 
// Output: 246

// String Concatenation
print(123 + "123"); 
// Output: 123123 (Notice how it glues them together instead of adding!)

// This is very useful for formatting outputs:
var lives = 3;
print("You have " + lives + " lives remaining.");