I'm going through some code of other game modes to figure out how they put things together, but I'm unfamiliar with Lua and GMod's framework so I have a few questions.
I read the Lua reference site, but perhaps there were a few things I didn't understand.
1. I see in TTT and Murder that they have some lines that go like
[CODE]
GAMEMODE.SomeThing = SomethingElse
// or something like this
GM.Something = SomethingElse
[/CODE]
To me, this looks as though he is assigning a variable on some GM class.
What are they doing here?
2. Other times I see this.
[CODE]
// custom file
function GM:CustomFunction ()
end
[/CODE]
Is the only purpose of this to be able to use [CODE]self.Whatever[/CODE] within that custom function? If "self" isn't used in those functions what is the benefit?
1.
Both GM and GAMEMODE refer to the currently active gamemode table, although they're both available at different times. So for your example it'd be assigning a variable in that table.
2.
There isn't any, sometimes it's just required.
Say for example you were to call a hook with `hook.Call`, that function automatically puts the gamemode table as the first argument when calling the gamemode hook. If you didn't create your function like in your example, then the arguments would be out of order.
[QUOTE=bigdogmat;51276310]1.
Both GM and GAMEMODE refer to the currently active gamemode table, although they're both available at different times. So for your example, it'd be assigning a variable in that table.
2.
There isn't any, sometimes it's just required.
Say for example you were to call a hook with `hook.Call`, that function automatically puts the gamemode table as the first argument when calling the gamemode hook. If you didn't create your function like in your example, then the arguments would be out of order.[/QUOTE]
For the first one, if that variable wasn't part of the table before, is it adding it to it? Would that basically make a variable that is accessible from any file?
That second one makes sense.
[QUOTE=cdub;51276351]For the first one, if that variable wasn't part of the table before, is it adding it to it? Would that basically make a variable that is accessible from any file?
That second one makes sense.[/QUOTE]
In LUA, everything is a table. Tables in tables in tables, and there is no restriction on what goes in them or when.
You can assign new variables at any time, to anything.
As long as you have an object reference in a file or have a way to find one, you can access anything from anywhere.
Sorry, you need to Log In to post a reply to this thread.