Results 1 to 10 of 88

Thread: Gs2 for the Noobs #1 - The Beginner's Guide!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825

    Post Gs2 for the Noobs #1 - The Beginner's Guide!

    Hey,
    I like writing a bunch of tutorials about stuff nobody likes, making them look more fun/easier.
    So let's get started with GS2.

    Small FAQ (YOU MUST KNOW, I KNOW THIS IS THE BORING PART):

    Q.What's Gs2?
    A.GraalScript 2, it's the language you type in, just like English, French and there's Gs2.

    Q.What can I do using Gs2?
    A.Create baddies, make calculations, create cool stuff you'll think it's boring!

    Q.Is Gs2 free?
    A.Sadly, no... You need to have a 'Gold Membership' and have to get hands on a server with the correct rights. (Can't find any servers? Post your GraalID on this thread)

    S.I've got a question!
    A.POST IT! I'd be happy to reply

    ---

    Okay, let's start.
    (if you already know how to setup your script editor, skip this step)
    Setting Up:
    • Get hands on a server's RC with weapon rights, press F6 in game, and a window like this one will popup:
    • Second, press the Script Editor button :
    • After that, select the Weapons folder, and press on (new weapon) :
    • Choose a weapon name, then press OK. (out of preference, name the weapon YourName/Test or something like that, e.g: John/TutorialTest)
    • After that, you'll have a text field on your right, that's where you can write text in! (for future references, this field is called a MultiLineEdit)


    The Coding part:

    You know the RC Chat, right? That's where the staff talks to each other... Well did you know, Graal can talk too? Yes it can, but you should make it send the text to the RC to be able to talk to you! For example:


    How did I do that?
    Scripted it!

    Okay so let me drive you into the steps one by one...
    The script that I used is:
    PHP Code:
    function onCreated() {
      echo(
    "Hey john, I'm Graal!");

    So, when you first see the stuff above you'll be like 'omg so many signs wth is the stuff I give up'.
    Let me explain it step by step.
    function is telling the compiler (the thing making your code into reality) that this script is called when this function is being triggered.
    Didn't understand? Good, cause I didn't either... But I'll be covering that after teaching you what the stuff inside that function means.
    For short, a function is a box, that has a to-do list in it...

    onCreated() is the 'key' of this box... Graal gives us a key called onCreated() as soon as you create the weapon/press Apply.
    For example, if you had 2 functions (boxes) called onCreated() and the other is called iLikeTunaYesIdo(), when you press Apply, Graal will give us a free key called onCreated(), then the script will automatically run the code in the onCreated() function/box. Yet again, I'll be covering this in the future...

    The { and } are called the curly brackets of the function, which is in fact, the parameter of the box/function. (look guys, I'm gonna call it function, just remember it's a box)... So whatever is INSIDE the brackets, belongs to the function / is inside the function. For example, when you open your fridge and see an apple, grape, beef and a murderer in your fridge, the function we will call 'fridge()' will have the stuff - and let's say you have another function called burger which contains ham, lettuce and tomatoes...
    Example:
    PHP Code:
    function fridge() {
      
    apple
      grape
      beef
      murderer
    }
    function 
    burger() {
      
    ham
      lettuce
      tomatoes

    (hope you got the concept)

    what's echo("something") ? It's a built-in graal function, which makes the thing you write (in this example, 'something') will be printed/said on RC. So basically if I change 'something' to 'HEY IT'S PIE DAY!' you'll have RC print out HEY IT'S PIE DAY! (remember to press apply)

    The ; is really important, it marks when the line is going to get read, for example, in order to make a burger correctly, you need to make it in this order: Bun, Lettuce, Ham, Other Bun.
    So the correct script for it is :
    PHP Code:
    function makeAYummyBurger() {
      
    Bun;
      
    Lettuce;
      
    Ham;
      
    Other Bun;

    (remember those are examples, these scripts will not actually work)
    This will place the Bun first, then lettuce, then the ham, then the other bun in that order.
    But if you forgot a semicolomn (;) there will be a bunch of errors, quick example :
    PHP Code:
    function makeAYummyBurger() {
      
    Bun;
      
    Lettuce
      Ham
    ;
      
    Other Bun;

    I forgot the semicolomn on the lettuce so it will be read as this:
    PHP Code:
    function makeAYummyBurger() {
      
    Bun;
      
    LettuceHam;
      
    Other Bun;

    And since Lettuce and ham cannot be mixed together, this will not work.

    All of the above was conceptualizing, if you want to do some actual coding, read the next step...

    Actual Coding:
    ** Small note:
    you can name your functions and variables (I'll talk about that) whatever you want.
    spaces do not matter, it's just for a nice coding style, so having:
    PHP Code:
    function onCreated()         {
    echo(
    "HIII");
                                                                      echo(
    "ELLO");






    Is the same as having :
    PHP Code:
    function onCreated(){echo("HIII");echo("ELLO");} 
    end of small note**

    Let's say we want to make Graal tell us what 1 + 3 is equal to, so what we have to do is:
    PHP Code:
    function onCreated() {
      echo(
    3);

    And this will print out 4 on the RC Chat.

    WARNING, if you use " " it will print out the text inside the brackets, for example echo("1 + 3"); will echo 1 + 3 not 4.

    Let's try another one, shall we? I want to know what 8 - 5 does, so:
    PHP Code:
    function onCreated() {
      echo(
    5);

    And this will print out 3...

    2 x 5 ? In scripting, times is not used by an 'x', it's used by that star you get by pressing Shift + 8 (*).
    Most likely echo(2 * 5); which will give 10;
    8 divided by 2, in scripting, the division sign is expressed by a slash (/).
    so echo(8 / 2); which is 4...

    But let's say I want to mix text with calculations, how can I do that?
    Here's an example:
    PHP Code:
    function onCreated() {
      echo(
    "Your number is "1);

    This will echo Your number is 2
    Don't panic!! The sign @ is used to connect strings (or chat if you want to call it like that)! For example, if I had echo("John" @ "Audi"); it will print out JohnAudi. There is also another sign called SPC, this is used for SPACES instead of @, take this as an example: echo("John" SPC "Audi"); will echo John Audi not JohnAudi (if this does not work, stick with having a space like echo("John Audi"); cause it doesn't matter really...).


    Remember in math class when they thought you about variables? For example, a variable called a = 5 so 1 + a = 6... That's what basically the whole idea of scripting is all about (well most of it)!
    Let's say I have a = 5; and I want it to echo a, what do to?
    PHP Code:
    function onCreated() {
      
    5;
      echo(
    a);

    WARNING, if you echo("a"); it will send the text 'a', if you echo(a); it will send the number 5 which is the value given to a.

    **Small Note:
    you can place comments inside your script to be able to find what you want easier, or for other developers to know what your doing.
    for example:
    PHP Code:
    function onCreated() {
      echo(
    "HI!"); // this will echo hi!

    the stuff on the right of these double slashes '//' will not be compiled, so only the stuff on the left.

    Another type of comments is the /* and */. What this does, is a 'Comments Brackets'... So everything in between those brackets will not be read by the compiler/the thing that does our script work.
    for example:
    PHP Code:
    function onCreated() {
      echo(
    "PIE PIE PIE!");
      echo(
    5);
    /*
      echo(4 - 2);
      echo("beef");

    the stuff in here will not be read, so the only things being echoed are PIE PIE PIE! and the number 8.
    */

    end small note**


    Did you know that a variable can contain calculations too?
    Let me name this variable 'i' and make it equal to the calculation of 3 + 2.

    PHP Code:
    function onCreated() {
      
    2;
      echo(
    i);

    Having i = 5, will echo 5.
    You can also have something like this:
    PHP Code:
    function onCreated() {
      
    1;
      echo(
    1);

    And this will echo 4... BUT, 'i' still have the value of 3, we only echoed i + 1, but we did not say i = i + 1;
    Confused? Cool, let me dive you trough that.

    Let me start by a basic example :
    PHP Code:
    function onCreated() {
      
    abc 4;
      
    abc 2;
      echo(
    abc);

    What will it echo? 4 or 2?
    It will echo 2, why? Here's how the compiler thinks:
    Hi, I'm the compiler.
    Let's see what I got here...
    PHP Code:
    function onCreated() { 
    Okay, so there's a function called onCreated(), I will give you a free trigger (key) for it! There you go...

    PHP Code:
    abc 4
    Alright, you want me to assign the number 4 to the variable abc, sure, *magic trick*... boom, now abc is 4, have a nice day!

    PHP Code:
    abc 2
    Hm, you already told me abc is 4, but if you want me to change that, I'm good with that, *more magic trick* and bam, abc is now 2.


    PHP Code:
    echo(abc); 
    You want me to print the value of abc? What was abc again? Oh right, 2, there you go... *prints the number 2 on RC*
    ---

    You can use more variables in the same script, you're not limited to a few!
    PHP Code:
    function onCreated() { // the name of the function
      
    tuna 35// tuna is now 35
      
    beef 4// beef has the number 5 assigned to it
      
    pork 1// and pork is 1 ...

      
    echo(tuna / (beef pork)); // omg what's this sorcery! It printed 7!
    }
    /*
    Let me explain what happened above
    In math class, you know that multiplications and divisions happens before the additions and subtractions.
    Like 2 * 3 + 4 / 2 does 2 * 3 first, then 4 /2 , the it adds them together, more of an example: (2 * 3) + (4 / 2)...
    (remember parenthesis's are met to be calculated first)

    so why did I have (beef + pork) in parenthesis? Because if I do not add them, it will divide tuna with beef, then add pork to it.
    So, echo(tuna / (beef + pork)); is like echo(35 / (4 + 1));

    */ 
    (check next post)
    Last edited by John; 06-05-2014 at 11:43 AM.
    -Johnaudi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •