What is the best way to learn Gmod lua?

Hello, I have been playing Garry’s Mod for a couple of years now, and I would like to learn to code!

I already know some basic things when it comes to gLua, but I want to know how to code more advanced scripts!
So, I was wondering, what’s the best way to learn glua?

http://forum.facepunch.com/showthread.php?t=1337945

First learn lua, then read and learn gmod lua off of the existing code in your garrysmod folder. Read the wiki to learn what the functions do.

If you do not know any other coding language i’d recommend you start off with an easier language than lua as it may be confusing for some at the beginning. Start with Java

Ratings probably give it away, but this is bad advice for a beginner who wants to start modding Garry’s Mod.

Lua is an excellent beginner’s language, with simple features that will directly translate to experience working with GLua.

Lua is a language that is harder to understand when you do not have any background.

You’d propose he learn a completely unrelated language based around a paradigm that is very different to Lua’s with a higher level of complexity?

Lua is by far the easiest language to learn as a beginner, you don’t have to worry about types, pointers, references, garbage, redefinitions … The list goes on.

Lua is VERY high level. I could understand your point in terms of C++ bindings or modules, but Lua itself is quite easy compared to Java, C++, or Python as a starting language

Lua is amazingly easy compared to low level languages like Java, thats terrible advice

There is a small part of me that agrees with this and the reasoning behind that is if you start with lua, primarily glua, where you have so many pre-made functions to work with (i.e timer.simple) from the get go with an environment to easily test and see your work in, you may struggle later on when you want to try another language and feel a bit lost (as I have since I desperately want to break out into general game development but feel overwhelmed). This is to the extend I agree with you, otherwise I think lua is a nice starting point.

On the other hand, you can basically take what I mentioned above and say it’s a good thing - you can dive straight into it, there’s always going to be instant visual feedback, etc.

The best way to learn lua in my opinion is to become self-sufficient and learn to think logically, which sounds pretentious. The amount of people, myself included, who will ask for help, clearly not think about what anything is doing or how stuff works then ask very basic questions when stuff goes wrong is astounding. Before making something, take a second to plan how to do it or how you think it’d work - things become so much easier that way!

I consider myself a novice scripter at worst, but an enthusiast at best.

Never look at something, and say you can’t make it. A misconception with early on lua developers is that they think people who create stuff, start the project knowing how to do everything it is that they want to do. As a beginner, this is not your case. You will start projects and not know how to do anything until you are standing in front of it, and if you’re dedicated and truly interested in learning, you will learn how to do it. Tutorials and guides only help you so much. Documentation and wiki entries are your friends, they are loyal and flexible. As a beginner, you will spend a lot of time on the Garry’s Mod wiki, looking at functions and their syntax.

I’m working on an elaborate drug system right now, and this is a very solid example of my statement above. Going into this project I’m working on, I had not done anything with Lua in over a year. Ontop of that, I don’t know a single thing about the chemistry behind manufacturing illegal drugs. I had never anticipated that this mod would require me to know stuff about vectors, angles, manipulating and networking information through various entities, and messing around with rendering settings. I also had no previous knowledge of anything - I had only edited TTT servers beforehand.

Now? I know a lot more about vectors, angles, rotation and how the location of the entity interacts with the world. I’ve mapped out every stage of production for many illegal drugs - I joke with my friend because for the past week, my googles searches have been refined to searches like “Methamphetamine production”, “Households products containing ___”, “How to make heroin”, and other really suggestive searches. I’ve learned an unimaginable amount of things since the beginning of this project, and most importantly, I’m doing something that I didn’t think I could. How? Every problem I ran into, I either a) troubleshooted, and fixed, b) searched for alternatives, c) found help on the forums. Lua is very very easy to troubleshoot and find work arounds compared to other languages. Definitely considering you don’t have to run through a compiler.

At last, I just want to tell you now. You’ll never learn unless you just try. If creating something from scratch is intimidating, then copy things from other people. Find a script that you like, and try to make it on your own. If you run into an issue, look at the script and see how that person worked it out. You’ll learn very important troubleshooting and logic from this. Then once you feel comfortable, move onto something bigger.

Add me on steam if you have any questions. I Love helping people with Lua, and I’m just returning the favor after so many people helping me in the past.

To be fair, almost everything made in glua requires the use of vectors or angles in some way.

The only time you’ll ever use vectors or angles is when doing stuff with entities (eg, finding within a box, placing at position, rotation, etc). I have programmed an entire gamemode and the only time I used vectors and angles was for the inventory system (placing hats on players), and the location system.

show off ;(

Thank you all for the replies!

Sorry I didn’t specify this when I posted the thread, but I already know basic lua, but the way i’ve heard it, glua is a modified version of lua. I just wanna know what to do to begin with glua.

Thank you.

What kind of stuff do you want to do?

Scoreboards, huds, etc…

Best way to learn that is probably to see how other people did it (like TTT’s HUD), though keep in mind that there’s a lot of shitty gamemodes and addons out here to learn bad habits from. If it looks like crap, it probably is.

If you want to start from scratch, the HUDPaint and ScoreboardShow/Hide hooks, and the surface and draw libraries, are gonna be your best friends.

Only you can answer the question in terms of how to learn a new language, skill, etc… Everyone learns differently; some learn by doing and others by reading and so on… I’d say Lua is incredibly easy to learn but it is also possible to pick up bad habits so it’s best, when learning, to also understand what is happening…

Some basic examples of that are as follows: Say you want to hide default hud elements… IF you use table.HasValue with a list of elements, in string form, you want to hide then understand each frame executes this hook 30+ times… So if you were to time it, it’d take around 15 seconds over 100 million executions ( with a list that has 6 or so items out of the 30+ possible items ) and that increases exponentially when you add in the fact that it is called 30+ times per frame to the tune of 495 seconds over 100 million simulated frames…

The same thing would happen ( but you’d shave 1 second ) if you use if ( x or y or z or a or b ) then return false; end because it’s doing the same thing a loop or table.HasValue would be doing… You’d end up comparing at best case 1 element and worst case would be comparing all of them.

You can simplify it to 0.08 seconds over 100 million executions and around 3 seconds over 100 million simulated frames. HUGE DIFFERENCE!

Just stay vigilant and read the wiki and other sources when creating things so you understand how they work.

Feel free to add me on Steam, I tutor and have written over 500 tuts that I share when questions are asked until I get my site back up.