Best way to learn how to script?

I’m wanting to learn how to lua script, mainly so I don’t to bug my friends when I get an idea for my sandbox server…

So, whats the best way to learn? I know about the wiki, but even after staring at that thing for hours my scripts usually end up as failures…

Start off with either this tutorial or the Lua documentation and then proceed with learning the custom features of GMod Lua including, but not limited, to the following pages:

Additionally, it’s a good idea to try out the articles you can find here to make your first SWEPs, SENTs and STOOLs.

Check out this thread: http://www.facepunch.com/showthread.php?t=868561

To be honest, I learned everything I know simply by making my own gamemode just by deriving base. It wasn’t anything special I admit, but it still tought me the basic concepts of garrysmod Lua.

Before I started making my own gamemode though, I made sure I was fairly sure on Lua syntax.

I just went and downloaded something that looked fairly simple and studied it, changed it up until I knew what things did, then I re-typed it so I knew what I was doing, and then reused some pieces from that item in another item to make a new item. From there I understood what functions did what.

As Overv said, follow those links, then try it out for yourself. What I did(am still doing actually) is I created a Lua file, and basically walked through Pil, noting stuff by the functions, keeping track, taking notes, etc. It helps you to see what color things are, so download the notepad++ syntax highlighter and notepad++ itself.

My next suggestion is to look at other people’s code if you need to base something around it or not. If I want to kill all players, I can look at a script that kills a player, study it, and change it to reflect my needs. Just don’t steal work.

Was able to make a spectating script just by looking at stuff from the wiki…



if ( SERVER ) then

function Spectate( ply )
        if ply:IsAdmin() then
		    ply:Spectate(6) 
			ply:StripWeapons()
			for _, v in pairs(player.GetAll()) do
			    v:ChatPrint( ply:Nick() .. " is now in spectate mode." )
		end
		else
		    ply:ChatPrint("You are not allowed to use this command!")
		end
	end
concommand.Add( "spectate", Spectate )

function EndSpectate( ply )
        if ply:IsAdmin() then
		    ply:UnSpectate()
		    ply:KillSilent()
			ply:ConCommand("+jump; -jump")
		    for _, v in pairs(player.GetAll()) do
		        v:ChatPrint( ply:Nick() .. " has exited spectate mode." )
	end
        else
		    ply:ChatPrint("You are not allowed to use this command!")
		end
	end
concommand.Add( "unspectate", EndSpectate )
end	
			


Thanks for the help guys, hopefully Ill get better at this as I go :v:

Well all I did was start a small project.
Download some files… change them up…
Add things in… and then try to make my own script related to the topic.

good luck :v:

[lua]ply:KillSilent()
ply:ConCommand("+jump; -jump")
[/lua]

wut

[lua]ply:Spawn()[/lua]

Umm, thanks for that. The concommand thing wast working anyways.