- Messages
- 5,093
- Reaction score
- 2,881
- Points
- 1,103
Hello
This is the first basic tutorial about GSC, first time about Functions, I will explain how are they and how to call them, gsc codes are all inside functions, by calling new functions you do different things in game.
The default function structure:
Example of the default function structure
The thing I called "Function1" is the name I put to the function, the "( )" is added because without it, is not a function (it is needed). Then there is a opening bracket ( { ), after it is where you are going to place your code and when you have ended writing it, you must close the function with a closing bracket ( } ). An example of function:
Something you cant make on a function is to put 2 functions in 1, example:
Call Functions
By adding a code to a file, it wont be enough to make it work, so, you´ll have to "thread"/call it. There are many ways, I´ll say a few of them, the most used one is this one:
This is the example Function which we will call in the following examples:
1. the normal calling looks like this:
2. Call a Function as a Input of a other Function.
Inputs of a Function
A function name can also have inside the "( )" variables which have some use inside the function, for example:
It will say first what I put in "thing1" and then what I put in "tutorial", for example, I could call it like this:
Question?
Ask them here.
Thanks for reading, @CabCon.
This is the first basic tutorial about GSC, first time about Functions, I will explain how are they and how to call them, gsc codes are all inside functions, by calling new functions you do different things in game.
The default function structure:
Code:
Function1( ) //Name of the Function Name
{
CODES HERE
}
Example of the default function structure
The thing I called "Function1" is the name I put to the function, the "( )" is added because without it, is not a function (it is needed). Then there is a opening bracket ( { ), after it is where you are going to place your code and when you have ended writing it, you must close the function with a closing bracket ( } ). An example of function:
Code:
SayTheWords()
{
self iPrintLnBold( "You are reading" );
wait ( 1 );
self iPrintLnBold( "Functions tutorial" );
}
Something you cant make on a function is to put 2 functions in 1, example:
Code:
FunctionA()
{
FunctionB()
{
SOMETHING
}
}
Call Functions
By adding a code to a file, it wont be enough to make it work, so, you´ll have to "thread"/call it. There are many ways, I´ll say a few of them, the most used one is this one:
This is the example Function which we will call in the following examples:
Code:
SayTheWords()
{
self iPrintLnBold( "You are reading" );
wait ( 1 );
self iPrintLnBold( "Functions tutorial" );
}
1. the normal calling looks like this:
Code:
self thread YOUR FUNCTION NAME;
Example:
self thread SayTheWords();
2. Call a Function as a Input of a other Function.
Code:
myTestFunction(function)
{
self thread [[function]]();
}
Example:
self thread myTestFunction(::SayTheWords); // :: will say that the variable "SayTheWords" is a function.
Inputs of a Function
A function name can also have inside the "( )" variables which have some use inside the function, for example:
Code:
SayTheWords2( thing1, tutorial )
{
self iPrintLnBold( thing1 );
wait ( 1 );
self iPrintLnBold( tutorial );
}
It will say first what I put in "thing1" and then what I put in "tutorial", for example, I could call it like this:
Code:
self thread SayTheWords2( "Hello CabConModding User", "You are reading Functions Tutorial" );
Question?
Ask them here.
Thanks for reading, @CabCon.