I like to think of functions as "add-on" commands to the language. For example, I will write functions like MakeBullet, MakeEnemy, MakeExplosion, etc. You've been using built-in functions all along with DB. For example, newxvalue, camera angle x(), etc. These are examples of functions that return a value. Other functions include "texture object, move object, position object, etc. In your function declaration, you put "aruguments" in the parentheses for the values you want the function to process, whether it is returning a value or you are telling it where you want to position an object.
Now, let's create a really simple function. We'll call it "addNum." You give it two values, and it adds them together.
function addNum(num1, num2)
NewValue=num1 + num2
endfunction NewValue
`putting a value after the "endfunction" command means you want the function to return that value.
Now, anywhere in your code where you want to add two numbers, you can use your addNum function.
answer=addNum(2,56)
print answer
`will print "58" to the screen
Of course the addNum function is really quite useless, but you could for example, create a function that finds the hypotenuse of a triangle. Here's a quick example:
print hypotenuse#(3.0,4.0)
wait key
function hypotenuse#(a#,b#)
hypot#=sqrt(a#^2 + b#^2)
endfunction hypot#
And of course the famous "distance" function:
Function Distance(object1, object2)
Distance#=sqrt((object position x(object1)-object position x(object2))^2+(object position y(object1)-object position y(object2))^2+(object position z(object1)-object position z(object2))^2)
EndFunction Distance#
Hopefully this helps a little.