Post: Quick and easy ways to clean up your script.
10-19-2014, 07:51 PM #1
Taylor
Former Black Knight.
(adsbygoogle = window.adsbygoogle || []).push({});
Hello Gsc Fanatics

I wrote this thread because I was sick of seeing poorly written functions being posted each day. They are sloppy and bad to look at.




  1. Toggles


    • Cluttered way.
          
      godmode_toggle()
      {
      if(self.godmode == false)
      {
      self EnableInvulnerability();
      self iPrintln("Godmode Enabled");
      self.godmode = true;
      }
      else
      {
      self DisableInvulnerability();
      self iPrintln("Godmode Disabled");
      self.godmode = false;
      }
      }



    • Clean way. You must login or register to view this content.
          
      godmode_toggle()
      {
      if(!isDefined(self.isGod) || !self.isGod)
      self EnableInvulnerability();
      else
      self DisableInvulnerability();

      self.isGod = !self.isGod;
      self iPrintLn("Godmode " + self.isGod ? "Enabled" : "Disabled");
      }

      Explanation: I use this method myself and it is overall better. It may look like more code however the toggle function can be re-used with multiple functions. So instead of writing the same two lines over and over again you have one function that you call that does it for you. As well as the toggle function itself being smaller.


  2. If statements and for loops.


    • Cluttered way.
          
      if(self.menuOpen == true)
      {
      for(i = 0; i < level.players.size; i++)
      {
      level.players[i] iPrintln("Menu is open");
      }
      }

    • Clean way. You must login or register to view this content.
          
      if(self.menuOpen)
      {
      for(i = 0; i < level.players.size; i++)
      level.players[i] iPrintln("Menu is open");
      }


      OR

          
      if(self.menuOpen)
      self iPrintln("Menu is open");

      Explanation: When using if statements and for loops, you do not need to add braces to your code IF AND ONLY IF the code that you would put between the braces is one line of code. Also you don't need self.menuOpen == true, self.menuOpen by itself works just as fine. If will read the variable as true because if(self.menuOpen) is like saying if(true). Likewise with variables that are false. You don't need self.menuOpen == false, if(!self.menuOpen) will read the variable as false.


  3. Function calling


    • Cluttered way.
          
      self thread function();

      function()
      {
      self iPrintln("I am NOT a looped function");
      }

    • Clean way. You must login or register to view this content.
          
      self function();

      function()
      {
      self iPrintln("I am NOT a looped function");
      }


      OR

          
      function();

      function()
      {
      self iPrintln("I am NOT a looped function");
      }

      Explanation: When a function does NOT contain a CONTINUOUS for or while loop, then you do NOT need to call it as a thread. You can just call the function normally on an entity you wish to call it on. However, in the last example that is clean I bet you noticed I did not define an entity. In this case, it is because if I call a function without an entity definition, it defaults to the entity that the scope is being called on.




If you would like for me to touch base on any other ways to optimize your code then please leave me a reply stating what you want an explanation for.

Thanks for reading!
- Taylor

[/font]
Last edited by Taylor ; 10-21-2014 at 12:12 PM.

The following 22 users say thank you to Taylor for this useful post:

-Numb, Chris, Cien, DJ_KILLA1337, DoraTheKiller97, Exelo, Father Luckeyy, Full-Evil, Geo, HiddenHour, ikilzu, iRnZ, KranK, Magnate13Snake, MCabCon, seb5594, ShutTheCrunchUp, SyGnUs, ViRuzModzHD, Fatality, xK ELITE GaminG, Zambie
10-22-2014, 12:54 AM #38
primetime43
Knowledge is power Tiphat
Originally posted by Taylor View Post
Well, you of all people know how the community is anymore. tears It's kind of sad actually.

what do you mean? Im not sure if thats a compliment or something bad.
10-22-2014, 02:36 AM #39
Taylor
Former Black Knight.
Originally posted by primetime43 View Post
what do you mean? Im not sure if thats a compliment or something bad.


It's meaning you are one of the OGs that are watching the community become a decrepit slowly.
10-22-2014, 06:53 PM #40
primetime43
Knowledge is power Tiphat
Originally posted by Taylor View Post
It's meaning you are one of the OGs that are watching the community become a decrepit slowly.


Haha ok... I'm a creeper :megusta:
You too mate!
Last edited by primetime43 ; 10-22-2014 at 06:57 PM.
11-07-2014, 05:55 PM #41
I have a problem i only get a error with GSC Studio bad syntax line 135 : You must login or register to view this content. could someone help me ? skype : TeamLogicModz
11-07-2014, 06:15 PM #42
SyGnUs
Give a F*** About Your Lifestyle
Originally posted by Christoph15 View Post
I have a problem i only get a error with GSC Studio bad syntax line 135 : You must login or register to view this content. could someone help me ? skype : TeamLogicModz


Probably because you have a comma on line 135 - wait 0,5; Use it like this - wait 0.5;
11-07-2014, 07:22 PM #43
Jeah i tried that but then i get a nother error and when i put a ( . ) to every ( , ) it wont inject ^^
11-22-2014, 02:57 PM #44
Adrian
Adrian is back!
for the toggles i am use to code the else part becz i coded C# for a long time so i would prefer the 1st one and it also looks cleaner
02-02-2015, 12:52 PM #45
One
At least I can fight
If you learnt correctly with good practices you don't need this, nice tutorial anyway I guess.
07-20-2015, 01:09 AM #46
royaltempers
Save Point
I'm making a menu and I have got godmode function and it works fine but when I add more functions I always freeze I have tried 3 different menu bases and I have tried Trickshot aimbot and no clip and unlimited ammo but I freeze could you please help me my Skype is connorosullivan141

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo