Where could I start to learn lua? I tried to use the tutorial on the Gmod wiki but it doesn't do good for me. I don't know where else I could learn it. Does anyone know?
[url]http://www.lua.org/pil/[/url]
Humblesnurp && [url]http://www.lua.org/pil/[/url]
Wiki helps a lot, I don't know why it doesn't give you any good. That's where I started. I also went to the above links. Another thing is too look at some codes and try to understand it. Basically you look at it like this;
[lua]
print("Hello World!")[/lua]
Obviously, it's printing out Hello World! . You read it as how it will come out. LUA in gmod isn't too difficult, and can come out to be something really fun. It takes a lot of time, but after the while you will get the hang of it.
One thing I did is look at codes on the wiki and rewrite them myself, so I could get the hang of it. This actually helps a lot because you put it into your brain on what your writing out and how it is done, then you know it.
Sites:
[url]http://wiki.garrysmod.com[/url]
[url]http://www.lua.org/pil/[/url]
Thanks Guys the links are really helpful!
You should first download Notepad++
[QUOTE=zzaacckk;26730386]You should first download Notepad++[/QUOTE]
don't listen to zack he's bad.
Says the guy who thought code in a button click event would loop.
Well, Notepad++ is actually a great tool for lua, if you have the glua plugin for it. It makes it a lot simpler to code, and it's easier to find errors and mistakes in it.
If you're getting into Lua for your first time, don't expect to get good instantly. Give it time.
The best way is to read the wiki constantly, and look at what other people ask in the Lua questions section here on facepunch. Look at what other people code, then try to rewrite it. One way is to edit their code, and try to understand it. When you think you've gotten good enough, make your own solo project from scratch. You don't have to release your first couple of projects.
Glua plugin for notepad PP
I'm thinking wiki doesn't work well for you because you don't know what you're looking for, you should post in the questions section more often with descriptions of what you're looking for, or just browse the site.
I don't think noobs should use the lua.org site just yet. I recommend making hud or something, start small and work your way up with wiki.garrysmod.com, then as you get better at lua, and as you understand more of the language, you can understand what the stuff on [url]http://lua.org/pil/[/url] means.
This was my very first Lua script.
[lua]
function jchud()
if !LocalPlayer():Alive() then return end
if(LocalPlayer():GetActiveWeapon() == NULL or LocalPlayer():GetActiveWeapon() == "Camera") then return end
draw.SimpleText(LocalPlayer():Health() .. " Health", "ScoreboardText", ScrW()*0.01, ScrH()*0.01, Color( 255, 104, 86, 255 ), 0, 0 )
draw.SimpleText(LocalPlayer():GetActiveWeapon():Clip1() .. " Primary Ammo", "ScoreboardText", ScrW()*0.01, ScrH()*0.05, Color( 255, 104, 86, 255 ), 0, 0 )
draw.SimpleText(LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetSecondaryAmmoType()) .. " Secondary Ammo", "ScoreboardText", ScrW()*0.01, ScrH()*0.07, Color(255,104,86,255),0,0 )
if LocalPlayer():Armor() > 1 then
draw.SimpleText(LocalPlayer():Armor() .. " Armor", "ScoreboardText", ScrW()*0.01, ScrH()*0.03, Color( 255, 104, 86, 255 ), 0, 0 ) return false end
end
hook.Add("HUDPaint", "jchud", jchud)
function hidehud(name)
for k, v in pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "hidehud", hidehud)
[/lua]
and this was my second
[lua]
if (SERVER) then
AddCSLuaFile("autorun/clock.lua")
end
if (CLIENT) then
function clockhud()
draw.RoundedBox( 0, ScrW()*0.01, ScrH()*0.01, 128, 46, Color( 25, 25, 25, 255 ) )
draw.RoundedBox( 20, ScrW()*0.01, ScrH()*0.01, 128, 46, Color( 125, 125, 125, 125 ) )
draw.SimpleText(os.date( "%a, %I:%M:%S %p" ), "Default", ScrW()*0.024, ScrH()*0.02, Color( 255, 104, 86, 255 ),0,0)
draw.SimpleText(os.date( "%m/%d/20%y" ), "Default", ScrW()*0.035, ScrH()*0.04, Color( 255, 104, 86, 255 ),0,0)
end
end
hook.Add("HUDPaint", "clockhud", clockhud)
[/lua]
and now I'm making addons that are hundreds and hundreds of lines. I haven't learned a thing from lua.org/pil, only wiki.garrysmod.com, other simple scripts, and good friends.
[editline]17th December 2010[/editline]
[QUOTE=blown25;26749579]Glua plugin for notepad PP[/QUOTE]
Just add your own syntax highlighting.
[QUOTE=Overv;26738654]Says the guy who thought code in a button click event would loop.[/QUOTE]
;[
I would suggest making small goals then just keep looking until you find out how to accomplish them. That's how i learned/am learning.
E.g. :
Make a button with derma that makes you say something when you click it. ([url=http://wiki.garrysmod.com/?title=Robotboy655%27s_Derma_Guide]Derma Guide[/url], [url=http://wiki.garrysmod.com/?title=G.RunConsoleCommand]RunConsoleCommand[/url])
Remake the status console command. ([url=http://wiki.garrysmod.com/?title=ConCommands]Console Commands[/url], [url=http://wiki.garrysmod.com/?title=Using_the_for_in_loop]For in loop[/url])
Other useful stuff:
[url=http://wiki.garrysmod.com/?title=Lua_Tutorial_Series]Wiki Tutorials[/url]
[url=http://luasearch.overvprojects.nl/index.php]Lua Search[/url]
[url=http://google.com]Your best friend[/url]
Also looking over other peoples code can help but try not to copy it :P
[QUOTE=Overv;26738654]Says the guy who thought code in a button click event would loop.[/QUOTE]
Wow really?
On Topic:
[url]http://luasearch.overvprojects.nl/[/url]
Really good for searching functions :D
And don't try to use the gmod wiki search. It is ridiculously horrible for finding hooks and functions.
I'd suggest using Luapad as a scripting aide. It allows you to write and execute Lua in-game. I know there are commands like lua_openscript and lua_openscript_cl, but this is REALLY useful.
I'd also suggest starting with simple things, and perhaps some simple Derma.
I found out instead of copy paste coding actually try and write the whole thing out! Then even commenting it in a nice neat manner can help also.
[QUOTE=mil0001;26847845]I found out instead of copy paste coding actually try and write the whole thing out! Then even commenting it in a nice neat manner can help also.[/QUOTE]
:doh:
Sorry, you need to Log In to post a reply to this thread.