Function?

Blitz3D Forums/Blitz3D Beginners Area/Function?

Functions make code managable. You can place them in other files(includes) and some editors can fold them(hide them). You can for instance place each part of a program/game inside a function.

Like below.
intro()
game()
outro()


The entire game would be called in these 3 lines of code, just by using functions. (Not that a game could be made in 3 lines)

Some extra info. Variables inside functions are not global. Every variable will be freed/forgotten when the function is finished.

To return a value from a function you should do :


print addition(10,10)
end

function addition(a,b)
return a+b
end function


Calling the 'Return' alone will exit the function at the point of calling.

Arrays/types and global variables can be accessed and modified from inside a function. You can not create global variables/arrays/types inside functions.

Functions can have predefined arguments.

Function addition(a=0,b=0,c=0,d=0)
return a+b+c+d
end function


Functions can return integers(this is default) Strings(text), or float values(0.42234 ect..)

Function mergestring$(a$,b$)
return a$+b$
End Function

Function Addfloat#(a#,b#)
return a#+b#
End function


You can create Blitz arrays inside functions. They do not have error checking, so do not use these until you know how they work.

Function dostuff(a,b,c,d)
Local stuff[3]

stuff[0] = a
stuff[1] = b
stuff[2] = c
stuff[3] = d

;and ect...

End function


This is all I can come up with at this time. Hit the documentation and look at examples is the best advice
i can give.