ItsMods

Full Version: Basic GSC Coding: Functions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello

This is my second basic tutorial about GSC, this time is about Functions, I will explain how are they and how to call them, gsc codes are mostly all inside functions, by calling new functions you do different things in game, a function structure is like this.

Code:
Function1( )
{
CODES HERE
}

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
    }
}

By adding a code to a file, it wont be enough to make it work, so, youll have to "thread"/call it. There are many ways, Ill say a few of them, the most used one is this one:

Code:
self thread YOUR FUNCTION NAME;

There are also this shortened versions for 2 things I am not explaining here:

Code:
self YOUR FUNCTION NAME;
YOUR FUNCTION NAME;

To call this function:

Code:
SayTheWords()
{
    self iPrintLnBold( "You are reading" );
    wait ( 1 );
    self iPrintLnBold( "Functions tutorial" );
}

You would need to call it like this:

Code:
self thread SayTheWords();

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 Itsmods", "You are reading Functions Tutorial" );

I hope you have liked it, any questions: just ask.

Thanks for reading, @Yamato
You know there is a difference between
Code:
self doShit();
and
Code:
self thread doShit();
right?

For example if the function doShit() would be:
Code:
doShit()
{
    wait 5;
    iPrintLnBold("Waited 5 sec.");
}

Main()
{
    doShit();
    iPrintLnBold("This will happen AFTER it waited 5 sec, because it went in the doShit function");
}
Main2()
{
    thread doShit();
    iPrintLnBold("This will happen instantaneously. And after 5 sec it will still say 'waited 5 sec'. ");
}
(03-01-2012, 17:49)Pozzuh Wrote: [ -> ]OMA

My explanations are Dumb Bitch
I edited the main post with the missing words, Tongue
(03-01-2012, 17:55)Yamato Wrote: [ -> ]OMA sucks!

Still wrong.

It's not a "short" version, it's just that one function is threaded. The CPU will switch really fast between these threads so it looks like they are running parallel.

If you don't use threads function1 will call function2 and wait for function2 to finish so function1 can continue.

Apart from that nice tutorial.
necesito saber mas para hacer mi propio code ? (perdon si te molesto con preguntas , es que soy muy n00b en GSC XD)
(03-02-2012, 04:57)VerifyerModderz Wrote: [ -> ]necesito saber mas para hacer mi propio code ? (perdon si te molesto con preguntas , es que soy muy n00b en GSC XD)

English forum only lol.
(03-02-2012, 04:57)VerifyerModderz Wrote: [ -> ]necesito saber mas para hacer mi propio code ? (perdon si te molesto con preguntas , es que soy muy n00b en GSC XD)

Nano saber mass Paper hacker my proper code? (Pardon is child molester. Console pregnancy, is cool oi, I'm n00b and gsc XD)
(03-02-2012, 09:45)Pozzuh Wrote: [ -> ]
(03-02-2012, 04:57)VerifyerModderz Wrote: [ -> ]necesito saber mas para hacer mi propio code ? (perdon si te molesto con preguntas , es que soy muy n00b en GSC XD) OMA

Nano saber mass Paper hacker my proper code? (Pardon is child molester. Console pregnancy, is cool oi, I'm n00b and gsc XD)

Fail. Tongue
Consoles are indeed pregnant
Pages: 1 2