Skip to content
Sten edited this page Oct 1, 2023 · 4 revisions

Variable Declarations

You can declare variables using the let or const keyword.

let variable = "hello"
const constant = "world"

If you use the let keyword the variable is able to be changed later in the code. If you use the const keyword you will never be able to change it after declaration.

Functions

You can use the fn keyword to define a function.

fn test()
{
    // Function body
}

The function creates a new scope, any variables defined within the function will not be able to be accessed outside of it.

fn test()
{
    let testvar = 69
    print("test: " + testvar)
}

test()
print(testvar) // This will give an error because `testvar` only exists within the scope of the test function

If Statements

If statements can ofcourse be created by using the if keyword.

if (condition)
{
    // Only run if the condition is true
}

An if statement will behave differently depending on the type you pass to it.

  • Number
    • num != 0
  • Boolean
    • bool == true
  • Other (any other type)
    • other != null

Unlike the function, the if statement doesn't create a new scope. Therefore this is valid code:

if (true)
{
    let test = "test text"
    print("if statement: " + test)
}

print(test)

Else

You can create if-else statements by using the else keyword after closing the if statement.

if (condition)
{
    // Run the code if the condition is true
}
else
{
    // Run the code if the condition is false
}

You can also create else-if statements by adding an if after the else keyword. This can be stacked infinitely.

if (condition)
{
    // Run the code if the condition is true
}
else if (other_condition)
{
    // Run the code if the condition is false and other_condition is true
}
else
{
    // Run the code if both conditions are false
}

Clone this wiki locally