[TUT] basic of understanding gsc

Topic created · 3 Posts · 47 Views
  • Understanding The Syntax

    The Curly Brackets Are Used To Define where the start & end of your func are

    Example on how to use curly brackets

        //Start of Func              
        //End of func 

    The Semi-Colon are used to define where a line will end

    EX 1 
    funcName(); //By Putting The Semi-Colon I Am Ending My Line So the Code Knows To Go To The Next Line
    EX 2
    for(i = 0; i < 15; i++)//this Example You Can See that The Semi-Colon are Seperate The Variables


    number = 6;
    funcName(number)//A Function With The Argument of being number 
    //an argument is only added when the func supports it if not keep blank 
    //as you can see

    what is to call soemthing

    so calling is when you added to a place to be used in EX
    will be to call it from a Menu so that will look soemthing like
    this self add_option("SubM1", "UFO-Mode", ::toggleUFO);
    and you can call it in init(), onplayerspawn(), onplayerconnect();


    threading is when we call a code that as the word thread in this EX it shows you on how a thread looks like and we will thread like "self thread saveandload();"

    	self endon("disconnect");
            if(self actionslottwobuttonpressed() && self GetStance() == "crouch")
                self.savedOrigin = self.origin;
    	        self.savedAngles = self.angles;	
    	        self iprintln("^2Saved location");
                wait 2;
            if (self actionslotonebuttonpressed() && self GetStance() == "crouch") 
    	        self setOrigin(self.savedOrigin);
    	        self.angles = self.savedAngles; 
            wait 0.05;

  • What's the difference in:

    thread init();


  • Long story short, threads are used to execute code at the same time or "asynchronously", as programmers like to call it.

    Take this example:

    def sumNumbers(n) {
       result = 0;
       for(var i = 0; i < n; i++) {
         result += i      
      return result;
    def funcOne() {
       self iPrintLn("Woops");
    def funcTwo() {
       thread sumNumbers(99999);
       self iPrintLn("Woops");

    The function sumNumbers will take a long time to sum all the numbers if n is high enough (i.e 99999).

    In funcOne, we call it without thread so it runs on the same thread as the rest of the function and thus blocks the function execution. That means that GSC has to wait until sumNumbers is done until print "Woops".

    In funcTwo, we call it with thread, so it will call a thread for itself and will not block funcTwo execution. GSC will print "Woops" before sumNumbers is done summing all numbers up to 99999.

    Does that make sense?

Log in to reply