| Code: |
|---|
|
Now, the word 'function' tells the program that you will be declaring a function. The next part of the function is the name of the function. You need to make sure your function has a unique name that no other function has, otherwise you'll get errors when saving a map. Next, you tell the program what the function 'takes' or needs pretty much. This function 'takes' a string, which is basically a message of some sort. After you put the type the function needs, you then have to put a name for it (so you can refer to it inside of your function). Lastly, you tell the program the type the function will return. You could make this a string, integer, real, and so on. However for this example, no value will be returned so we put 'nothing'.
After declaring a function, inside the function you need to put what the function does, otherwise it would be pretty useless. This function simply calls another function using the string value that is needed to call it. Lastly, you need to tell the program when the function ends, you do this by putting 'endfunction' at the end of the function.
| Code: |
|---|
|
This line would call the function I just showed you. When calling a function this way, you need to have the word 'call' followed by the function name which is then followed by parenthesis with the values the function takes inside of them. If a function takes multiple values, they are each separated by a comma ',' like in the DisplayTextToPlayer function. It works that same way when declaring functions too (whoops forgot to mention that earlier)
Now, I will go over what the return values in functions are. They're pretty simple really, though I don't want anyone to be confused about
anything. When a function has a return value, you can set variables that are the same type as the return value to that function. Here's an example:
| Code: |
|---|
|
Now, see that when you set a variable to the return value of a function, you don't need the word 'call'. Also, if you want to pass the return value
of a function, you don't need to put the word 'call' either, as seen with the Player function that was the needed parameter in the GetPlayerName function.
Also, and this is important when declaring a function, if the function declaration states that the function returns a value, somewhere in the function
if must have a line that 'returns' the value, like so:
| Code: |
|---|
|
There is one last thing you need to know when calling functions, you can only call a function that is above another, since that may not make complete sense,
here's an example:
| Code: |
|---|
|
Now, this is only used as a visual example so I can more easily describe what I was saying. You can only call a function that is above the function you are currently in. So, 'SomeOtherFunction' would be able to call 'SomeFunction'. However, 'SomeFunction' wouldn't be able to call 'SomeOtherFunction'.
| Code: |
|---|
|