Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial Basic GSC Coding: Functions
#1
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
Reply

#2
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'. ");
}
[Image: MaEIQ.png]
Reply

#3
(03-01-2012, 17:49)Pozzuh Wrote: OMA

My explanations are Dumb Bitch
I edited the main post with the missing words, Tongue
Reply

#4
(03-01-2012, 17:55)Yamato Wrote: OMA sucks!

[Image: MaEIQ.png]
Reply

#5
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.
[Image: azuw.jpg]
Reply

#6
necesito saber mas para hacer mi propio code ? (perdon si te molesto con preguntas , es que soy muy n00b en GSC XD)
Reply

#7
(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.
Reply

#8
(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)
[Image: MaEIQ.png]
Reply

#9
(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
Reply

#10
Consoles are indeed pregnant
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tutorial] Basic GSC Coding: Building your first mod and your first code Yamato 2 11,205 06-07-2016, 21:49
Last Post: FrostbytePG
  [Tutorial] Basic GSC Coding: Making your second code Yamato 9 8,636 12-28-2012, 13:30
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Operations Yamato 0 8,004 04-04-2012, 13:07
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Foreach, Continue and Return Yamato 6 7,574 04-04-2012, 08:33
Last Post: Yamato
  [Tutorial] Basic GSC Coding: Switch Yamato 6 6,035 04-03-2012, 18:32
Last Post: tsoPANos
  [Tutorial] Basic GSC Coding: If, Else and Else If Yamato 2 5,795 03-30-2012, 10:47
Last Post: alvarogt95
  [Tutorial] Basic GSC Coding: Downloading and Installing a mod Yamato 1 5,195 03-30-2012, 10:42
Last Post: alvarogt95
  [Tutorial] Basic GSC Coding: For Yamato 4 5,925 03-26-2012, 18:39
Last Post: tsoPANos
  [Tutorial] Basic GSC Coding: While, Break and Wait Yamato 6 7,516 03-06-2012, 13:48
Last Post: Yamato

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.