• Structuring the code in the LUA files
    39 replies, posted
Hey Facepunchers! I'm trying to edit some LUA files that I got from a gamemode just for fun but I find it really hard to get a nice structure on the code since all of it is just moshed together in a big mess. Is there any way to structure the code in the LUA files easily?
If you're talking about how you should whitespace your code, this is how I do it. If you're going to structure already existing code, you need to probably use search & replace. [lua] function SomeFunction(args, stuff, moar) if(stuff == true) then print(args, stuff, moar); else print("Too bad"); end player.GetAll()[1]:ChatPrint("Hey"); end SomeFunction("I", true, "like pie"); [/lua]
[QUOTE=DarKSunrise;17002521]If you're talking about how you should whitespace your code, this is how I do it. If you're going to structure already existing code, you need to probably use search & replace. [lua] function SomeFunction(args, stuff, moar) if(stuff == true) then print(args, stuff, moar); else print("Too bad"); end player.GetAll()[1]:ChatPrint("Hey"); end SomeFunction("I", true, "like pie"); [/lua][/QUOTE] You forgot Tabs! [lua] function SomeFunction(args, stuff, moar) if(stuff == true) then print(args, stuff, moar); else print("Too bad"); end player.GetAll()[1]:ChatPrint("Hey"); end SomeFunction("I", true, "like pie"); [/lua]
[QUOTE=DarKSunrise;17002521]If you're talking about how you should whitespace your code, this is how I do it. If you're going to structure already existing code, you need to probably use search & replace. [lua] function SomeFunction(args, stuff, moar) if(stuff == true) then print(args, stuff, moar); else print("Too bad"); end player.GetAll()[1]:ChatPrint("Hey"); end SomeFunction("I", true, "like pie"); [/lua][/QUOTE] i hope this isn't the way you indent your code
Ugh, my browser messed that up.
[QUOTE=DarKSunrise;17002521]If you're talking about how you should whitespace your code, this is how I do it. If you're going to structure already existing code, you need to probably use search & replace. [lua] function SomeFunction(args, stuff, moar) if(stuff == true) then print(args, stuff, moar); else print("Too bad"); end player.GetAll()[1]:ChatPrint("Hey"); end SomeFunction("I", true, "like pie"); [/lua][/QUOTE] Hey, thanks for the reply! I'm very new with this, I just want to add some things to the code of a gamemode but I can't really find a pattern in the code since it's just messed up. I'm trying to edit the init.lua file but the code is really long in a very few rows, I want to get the code easier to read somehow. Can I ask what program are you using when you're editing code etc? I just use the notepad lol, I guess you're using something else xD As I said, I'm a big newbie to this.
Notepad ++
Use Notepad++ with the GM10Lua plugin and don't indent your code like DarKSunrise. Do it like Commander204. edit: but don't put ;'s after each line that is fucking gay
[QUOTE=Retirsch;17002659]Notepad ++[/QUOTE] Okay, thanks! I'll try it now. [editline]04:28PM[/editline] [QUOTE=ninjerss;17002678]Use Notepad++ with the GM10Lua plugin and don't indent your code like DarKSunrise. Do it like Commander204. edit: but don't put ;'s after each line that is fucking gay[/QUOTE] Haha okay! Thaks a lot guys, I'll start googlin' right away! ^^
Whenever someone asks me about coding ethics, I always tell them the ten commandments of Lua scripting that I follow: [b]1.) For every function, thoust must end it. 2.) For every if-statement, thoust must end it. 3.) For every do-statement, thoust must end it. 4.) Thoust shall tab everything inside a function. 5.) Thoust shall tab everything inside an if-statement. 6.) Thoust shall tab everything inside a do-statement. 7.) Thoust shall leave a blank spot between function blocks 8.) Thoust shall block code of a similar intent 9.) Thoust shall keep simple statements in a single line (if not Var then Var = Value end) 10.) Thoust shall always optimize[/b]
[QUOTE=Gmod4ever;17002906]Whenever someone asks me about coding ethics, I always tell them the ten commandments of Lua scripting that I follow: [b]1.) For every function, thoust must end it. 2.) For every if-statement, thoust must end it. 3.) For every do-statement, thoust must end it. 4.) Thoust shall tab everything inside a function. 5.) Thoust shall tab everything inside an inf-statement. 6.) Thoust shall tab everything inside a do-statement. 7.) Thoust shall leave a blank spot between function blocks 8.) Thoust shall block code of a similar intent 9.) Thoust shall keep simple statements in a single line (if not Var then Var = Value end) 10.) Thoust shall always optimize[/b][/QUOTE] how does it feel being a giant tool
[QUOTE=Gmod4ever;17002906]Whenever someone asks me about coding ethics, I always tell them the ten commandments of Lua scripting that I follow: [b]1.) For every function, thoust must end it. 2.) For every if-statement, thoust must end it. 3.) For every do-statement, thoust must end it. 4.) Thoust shall tab everything inside a function. 5.) Thoust shall tab everything inside an inf-statement. 6.) Thoust shall tab everything inside a do-statement. 7.) Thoust shall leave a blank spot between function blocks 8.) Thoust shall block code of a similar intent 9.) Thoust shall keep simple statements in a single line (if not Var then Var = Value end) 10.) Thoust shall always optimize[/b][/QUOTE] Sounds great! Thanks for the advice! :D
[QUOTE=ninjerss;17002924]how does it feel being a giant tool[/QUOTE] How does it feel being a giant cunt? To answer your question, great. Whenever someone needs help tightening a bolt, I don't even need to go grab my toolbox.
[QUOTE=Gmod4ever;17002944]How does it feel being a giant cunt? To answer your question, great. Whenever someone needs help tightening a bolt, I don't even need to go grab my toolbox.[/QUOTE] Haha, n1. [editline]04:46PM[/editline] [QUOTE=ninjerss;17002924]how does it feel being a giant tool[/QUOTE] Come on, he just tried to help ^^
Don't use any kind of NP++ plugin that shows you the functions, I have never have. You don't really need to... or maybe I've just been coding Lua for GMod for so long that I know everything off by heart... oh how sad.
[QUOTE=Conna Wiles;17003670]Don't use any kind of NP++ plugin that shows you the functions, I have never have. You don't really need to... or maybe I've just been coding Lua for GMod for so long that I know everything off by heart... oh how sad.[/QUOTE] I've never bothered with it either. If you're unsure of a function, just look it up on the wiki...
[QUOTE=Conna Wiles;17003670]Don't use any kind of NP++ plugin that shows you the functions, I have never have. You don't really need to... or maybe I've just been coding Lua for GMod for so long that I know everything off by heart... oh how sad.[/QUOTE] Haha lol, okay :P I don't use any plugins at all. [editline]05:41PM[/editline] [QUOTE=Retirsch;17004018]I've never bothered with it either. If you're unsure of a function, just look it up on the wiki...[/QUOTE] Okay, I'll do that! Thanks.
[QUOTE=Retirsch;17004018]I've never bothered with it either. If you're unsure of a function, just look it up on the wiki...[/QUOTE] Or use Overv's awesome search thing. I love it because it shows the arguments, in the search itself.
[QUOTE=Jawalt;17004341]Or use Overv's awesome search thing. I love it because it shows the arguments, in the search itself.[/QUOTE] Okay, I'll check it out. Thanks!
[QUOTE=LiX;17004037]Haha lol, okay :P I don't use any plugins at all.[/QUOTE] I really suggest you use this plugin [url]http://www.facepunch.com/showthread.php?t=477505[/url] It will make finding syntax errors and reading your code much more easier.
[QUOTE=Crazy Quebec;17004738]I really suggest you use this plugin [url]http://www.facepunch.com/showthread.php?t=477505[/url] It will make finding syntax errors and reading your code much more easier.[/QUOTE] Allright, looks nice. Thanks! :D
Don't forget good old auto complete built into np++, very handy at times: [url]http://www.facepunch.com/showthread.php?t=588255[/url]
[QUOTE=JSharpe;17005161]Don't forget good old auto complete built into np++, very handy at times: [url]http://www.facepunch.com/showthread.php?t=588255[/url][/QUOTE] Allrighty, thx!
[QUOTE=JSharpe;17005161]Don't forget good old auto complete built into np++, very handy at times: [url]http://www.facepunch.com/showthread.php?t=588255[/url][/QUOTE] Does it complete automatically instead of needing CTRL-SPACE?
[QUOTE=Overv;17006022]Does it complete automatically instead of needing CTRL-SPACE?[/QUOTE] Near the bottom of the 1st post i quoted SteveUK with his Listen Up tip.
That's just lazy, JSharpe.
[QUOTE=Conna Wiles;17021678]That's just lazy, JSharpe.[/QUOTE] So is driving a car to the shop around the corner. But people still do it.
[QUOTE=Conna Wiles;17021678]That's just lazy, JSharpe.[/QUOTE] I don't know about you, but I'd absolutely lovely Visual Studio-styled intellisense / auto-complete. Would make my life so much easier.
[QUOTE=Kogitsune;17021749]I don't know about you, but I'd absolutely lovely Visual Studio-styled intellisense / auto-complete. Would make my life so much easier.[/QUOTE] It's just a shame parameter hinting within NP++ doesn't fully support the lua language syntax.
It would be nice if all those Gmod Lua specific editors that have been started would actually finish.
Sorry, you need to Log In to post a reply to this thread.