What's GM and where can I see all those functions ?

So, it’s a beginner question.

I understand classes, but I don’t understand what does “GM:…” means, is it a sort of namespace who says that the function is a native function ?

For example:

“function GM:PlayerSpawn( ply )”

Where can I find the documentation about those functions because I didn’t found it on the wiki or I’m maybe blind. And for me the Lua function list on the wiki is totaly broken (Error: Not Found / The requested URL was not found on this server).

Ty for your help and sorry for my poor english.

GM is the gamemode table.
You can only use it when gamemode is intializing, such as your init.lua file in your gamemode.
You can’t use it when gamemode has fully loaded, after that you need to use GAMEMODE.

Okay so GM is a table with function’s pointers in it ? Or is it a class ?

And sorry to ask so many questions but I realy can’t find a list of contained functions, is it on the wiki ?

[editline]17th May 2013[/editline]

Okay I begin to understand it’s an hooks composed class ?

Thank you for your help !

GM is a table of hooks that are called whenever an event, which may be useful to gamemodes, happens. You can see a list and description of the hooks here: http://wiki.garrysmod.com/page/Category:GM_Hooks

and here’s a description of hooks if you need it: http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index64f4.html

I had some problem to understand the logic of LUA programation because I alway work with C and C++ and the fact that there is no main function in LUA was realy disturbing me.

So if I understand well the only interaction between Gmod and my Script is those hooks ?

And thank you for giving me some of your time ^^’

I’m sure there are exceptions, but for 99.9% of all coding project I have done, the majority of stuff happens in the hooks. The equivalent of main is pretty much the lua file itself. If you were to just make a lua file that had a single print message at the top, that message would execute once, similar to how it would be done in main. However, if you put it in a function called in a hook, it would be called whenever a hook is called.

C++ knowledge is actually pretty useful in gmod. If you didn’t know, you can make C++ modules that allow you to bind code to lua functions and use them in-game. People have done everything from making bindings to logitech keyboard screens to adding support for controlling itunes.

Okay so I could build my gamemode in C++ and make hooks call my C++ module ? Because I heard that if you want to create a new variable type in LUA you have to use meta tables and it seems me easier to use C++ classes.

Tables are just organized variables. Strings, floats, and bools are the only data types there are in Lua. Other than that, every other data type are just glorified tables. A player is just a table that has all the details which classify it as a player. A color is just a table consisting of red, green, blue, and alpha.

If you want to make a new data type, do something to the effect of:
function Fraction(numerator, denominator)
return {num=numerator, den=denominator}

–then you can use it like this:
local frac=Fraction(5,3)
print(frac.num, “/”, frac.den)
–output: “5/3”
With tables, everything is possible. You can even have tables within tables within tables.
Seriously. Tables.
I sometimes find a little bit of splooge in my pants after I make a table. I just love them so much.
Now, if you’ll excuse me, I need to go clean my pants, as I have just soiled myself several times over.

I’m not sure how well that would work, it is much faster for lua to rely on its own code rather than external C/C++ code, despite the better performance of C++. Anyways, lua is a scripting language and should be easier to write than C++ once you get the hang of it.

[editline]17th May 2013[/editline]

Anyways, you shouldn’t need to create a new variable type unless you want to work with vectors or something, and even then there are very nice vector tables already made by other people.

I list with all the Game modes Hooks.

Almost everything you will ever need for GMod Lua.