to add onto that.
you use a function USUALLY when you have some code that you use over and over throughout your program. because then you type it once at the bottom of your code and can call it from anywhere in the program.
To clarify Variables are not "destroyed" they just don't exist outside the function.
if you use a variable in a function the next time you call that function the variable will still have the same value (inside the function)
so lets say you were making a calculator. you could use a function to do different things. like add,subtract,divide, and multiply so lets use the add funcion as a example.
Function Add(Number1,Number2)
Sum = Number1 + Number2
endfunction sum
The code:
Function Add(Number1,Number2)
declares the function and says that it will take 2 parameters,
and the parameters are integers. the names you specify here are the variables the function will put these values into.
Next:
Sum = Number1 + Number2
Just the stuff the function does pretty simple lol just adding
Next:
Endfunction sum
This ends the function and returns the value of sum(Note: the value of some the next time the function is called will still be the same. but for this function that does not matter. but can cause problems with other functions.)
Ok thats how you create a function. but how do you use them?
just call there name:
Variable = Add(44,56)
would set variable equal to the sum of 44 and 56(100)
In addition to endfunction there is exitfunction. unlike endfunction the exitfunction command is optional and can be placed anywhere in the function. it can also return a value. so it is pretty much endfunction but can be repeatedly placed throughout the function.
Ok well I'm not sure if you needed that much info but just in case i wrote it hahaha
and like that1smartguy said you can look at them like the simple commands thats what they are essentialy they are your own commands that you make. hope that helps.
New Site! Check it out \/