Function
✏ Beginners Scripting Guide ✏
Last updated
✏ Beginners Scripting Guide ✏
Last updated
In this section, we will be discussing about function. A function is a code of block that can hold another code of block and can execute the code block that was stored in the function multiple times by using parentheses to call out the function.
Making a function is the same as making a variable. But it is just a little bit different. Instead of:
We can do it like this:
Now we have a function. But the function will not run yet unless you call it. To call it we will get it name and put parentheses after the name like this:
A function also be GLOBAL and LOCAL. GLOBAL means it can be accessed everywhere in the script and LOCAL means it can be only accessed in a certain block of codes. It is the same as GLOBAL and LOCAL variable.
Now let's say we want the function to print the total sum of 2 numbers that was given in the function when it was called. We can start doing that by making 2 parameters with different names like this:
Now we are adding 2 parameters together and printing it in the function:
Now we gonna call the function and pass in 2 arguments for the function:
Return can be used to return data to the function or just break the function to prevent the code below from running.
To return data, we must make a function first and then use return
and put the data that we want to return to the function after the return