Custom Functions
Sometimes the functions supplied by CT and addons just won’t do it. Here’s how to write your own functions! You can even nest functions in functions
Basic Syntax
Generally, you declare a static using:
The things in brackets are optional, depending on what you want to achieve. Let’s take a closer look at specific functions.
Static Functions
Static functions are created before the script is run and can be accessed from anywhere in the script.
You can even access functions declared outside the script using the cross-script reference.
Void functions
Void functions are functions that will not return any value.
Return functions
You can also specify a value that should be returned by a function.
It is recommended using the as
keyword to define the return type.
Default arguments
You can also set some parameters default value. These parameters can be ignored and use default value when you call the function.
- You can use bracket handlers and functions for default arguments. But variables are not allowed.
- Once a parameter has a default argument, the parameters after it also require a default argument.
Functions as variables
You can also use functions like variables. In this case, they will be created as separate classes. Other than that, they work pretty much the same as static functions, you call them by their variable name.
You can even use them as global variables this way.
If you need to cast the method (as you do for globals) you can use this: