Structuring the code in the LUA files

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]

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]

i hope this isn’t the way you indent your code

Ugh, my browser messed that up.

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

Okay, thanks! I’ll try it now.

[editline]04:28PM[/editline]

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:

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

how does it feel being a giant tool

Sounds great! Thanks for the advice! :smiley:

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.

Haha, n1.

[editline]04:46PM[/editline]

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.

I’ve never bothered with it either. If you’re unsure of a function, just look it up on the wiki…

Haha lol, okay :stuck_out_tongue: I don’t use any plugins at all.

[editline]05:41PM[/editline]

Okay, I’ll do that! Thanks.

Or use Overv’s awesome search thing. I love it because it shows the arguments, in the search itself.

Okay, I’ll check it out. Thanks!

I really suggest you use this plugin http://www.facepunch.com/showthread.php?t=477505

It will make finding syntax errors and reading your code much more easier.