How to understand GLua better.

Does anyone have any advice or know how can someone (ME) understand GLua better ?
I asked a few coder and they were saying that I should read someone’s else code. I looked in to other people code but I couldn’t understand to much because I know the basics but I don’t understand how they create custom function and what they have to use to make them, what parameters and things like that.
I hope someone will know how other people like me could understand it better.

Q: How did you learned LUA ?

I suggest reading the first three chapters of the official lua guide to get basics dow

In case you don’t already know…
Gm12 wiki (copy hosted by someone else)

And the new one

These are the most helpful.

I pretty much know the basics. I can’t say i’m a complete noob at GLua.
The thing is the only things I can do are HUD’s, Scoreboards and Derma Menus.
But I want to know for example how to make: Round System, Spectator Mod,Money System,XP (I guess once I know how to do things like this I will know how to make custom function.)

[editline]30th May 2013[/editline]

I use them a lot but sometimes there are things I can’t find.

It’s important to know exactly what you’re trying to make before you make it.
It may sound like a simple concept, but a vision without structure is doomed to fail.

When you come up with an idea for an addon, you need to know exactly what you want. You need to know exactly how the system must function. Do you get XP for killing a monster? Do you get it for the last shot or do you get some for hurting it too? How much? Is there a modifier? What is that defined by? How do players open their level menu? How do they assign points? How are these points saved? A little planning can go a long way, especially with Derma and HUDs.

Before you start making anything, always ask yourself three things:
What will it do? --What is the function of my script?
How will it work? --How will it function?
How can I make it? --How do I make this work with Lua?

Once you’ve answered these questions to yourself, you can start working on it. If it involves some sort of VGUI, you’ll want to design that in paint beforehand. Never leave questions about your addon unanswered, and don’t start something that you know you can’t finish.

Follow those tips and you’ll be golden, ponyboy.

Every time I want to do something first I think what I want it to do.
For example I wanted to a panel and you can select a color basically the color is the theme. I have the VGUI but I don’t know how to make it so it will save it. I was thinking to use first time a txt file which will save the color and the steamid but I don’t know how, that’s my problem don’t know how to start and if I just look on wiki I can’t find the answer for something like that.

For more specific questions, Facepunch is always there for you.
If you want to write a file, you use file.Write(“directory/name.txt”, “Whatever You Want To Write”)
If you want to read a file you wrote, use file.Read(“directory/name.txt”, “DATA”)

for example
[LUA]
file.CreateDir(“money”)
function SetMoney(ply,money)
file.Write(“money/”…ply:SteamID64()…".txt", money)
end
function ReadMoney(ply)
return file.Read(“money/”…ply:SteamID64()…".txt", “DATA”)
end
[/LUA]

That will allow you to save and load money of a player.
Just set their money with SetMoney and read their money with ReadMoney.

A good thing to note is that you can save simple variables such as numbers and strings with ply:SetPData() and ply:GetPData(). This only works on the server though.

Thanks, that helped me a little, but the thing is you can’t post every time you need something and when you want to something more complex like a shop menu you can start asking question about how to make one and things like that. That’s why you have to understand GLua better and know how to use it.

Add me on steam and I can help you whenever you need it.

In case you haven’t already, I suggest you learn a tiny bit of the Net library! It is VERY helpful.

Just a tip: Pre-cache every net message. Both to and from the server, I was stupid and it took me a while to figure that out.

I know I have to learn them because I had to use them in past but it was a pain in the ass and I wasn’t trying to do anything complicated. But I still don’t know how to use them and it’s very hard to learn it.

The net library is just as easy to use as usermessages.

I don’t see what’s so hard to understand when panda linked you a tutorial on exactly how to use them.

If you want to understand LUA better I suggest you look and some amazing scripts and for each function or variable you don’t know what it does then search up what it means. As well try using that functions yourself. It helped me a lot.

In my opinion the usermessage it’s easier to use since I understand that but I didn’t understand the .net
And I looked over that at least 10 times but I just can’t figure out how to use it.

Here’s a quick example then.
[lua]
if SERVER then
AddCSLuaFile()
util.AddNetworkString(“OurMessage”)
hook.Add(“PlayerInitialSpawn”, “SendNetmessage”, function(ply)
timer.Simple(1, function()
if !IsValid(ply) then return end
net.Start(“OurMessage”)
net.Send(ply)
end)
end)
else
net.Receive(“OurMessage”, function(len, ply)
chat.AddText(Color(255,255,255), “Welcome to the server!”)
end)
end
[/lua]

I kinda start understanding net better but there are still things that confuse me and I should start checking them and see how to use them.

Ask them here while you’re at it, It’s not like we won’t help if you show us you will try.