Skip to content

Functions

Julius Paffrath edited this page Feb 18, 2025 · 5 revisions

Calling functions

A function in jask consists of a name and optional parameters:

; no parameters
myFunction()

; one parameter
myFunction(myParameter)

; two parameters, separated by a colon
myFunction(param1:param2)

Creating functions

Creating own functions in jask is very easy:

function myFunction(param1:param2)
    printLine("This is the first parameter: ":param1)
    printLine("And this is the second: ":param2)
end

Be aware: When using parameters, jask uses passing by value not by reference. Learn more about this topic here.

Functions can return nothing, any type of data or calculations:

function myFunc()
    print("Functions are great!")
end

function returnString(str)
    return str
end

function plus(num1:num2)
    return num1 plus num2
end

The call operator

If you want to call a function several times, you can do this:

run i to 10 with i plus 1
    printLine("i is ":i)
endrun

Or you can use a while loop:

while val equals TRUE
    printLine("val is TRUE!")
endrun

If the body of the loop consists only of one statement, you can use the call operator instead:

call printLine("Hello!") 100 times

This will call the function 100 times and is more readable.

Clone this wiki locally