The syntax for functions is as follows:
Example:
func fibonacci(x: Number) returns Number:
if x <= 1:
return x
else:
return fibonacci(x - 1) + fibonacci(x - 2)
info(fibonacci(10))
Output:
55
For a non-returning function, remove the returns subclause in the function header, as well as the clause in the function body.
Example:
func printMe(txt: Text):
txt2: Text = "00" + "0"
txt2 += "0"
txt += txt2
info(txt)
printMe("#FF")
Output:
#FF0000
IMPORTANT: Since draw commands should be placed at the end of the source code, they cannot be enclosed inside functions. A workaround is to return the object to be drawn, then draw it outside the function.
Example:
func draw_circles(x: Number) returns Number:
if x == 0:
return 0
y += 30
circles += circles(60, y, 20)
draw_circles(x-1)
return 0
circles: Object = circle(60, 20, 20)
y = 20
draw_circles(3-1)
circles.draw(1, 1000)