I've seen it used in g.FindMetaTable but I'm confused as to what self: actually refers to
[url]http://wiki.garrysmod.com/?title=G.FindMetaTable[/url]
If it refers to the ply, why can't you just use ply? Is self: referring to the executer of said script?
If you have a meta function, self will be the object the function was called on.
For example, if you have an object with the function :GetBla() then then the function could be defined like this
[lua]
function obj:GetBla()
return self.bla;
end
[/lua]
oh ok: then i'm guessing the metatable's self object refers to that of the current player? (or "player")
edit: pretty much the same thing as referring to the current object
self is a syntactic sugar variable used in OO lua. The object is defined by
[lua]function obj:Whatever(args)
end[/lua]
Which is equivalent to
[lua]function obj.Whatever(self,args)
end[/lua]
so yes, self refers to the object, which would be a specific player.
For example, if you were to call LocalPlayer():SomeFunc() then it would be basically doing
FindMetaTable("Player").SomeFunc(LocalPlayer())
Or, "Man Whithout Hat" you could not be a noob and do _R.Player.SomeFunc( LocalPlayer() );
[QUOTE=Stonna;32691786]Or, "Man Whithout Hat" you could not be a noob and do _R.Player.SomeFunc( LocalPlayer() );[/QUOTE]
Hardly makes him a noob, he contributed and helped the op, you trying to show him up was pointless and only makes you look like a douchebag.
[QUOTE=Averice;32693388]Hardly makes him a noob, he contributed and helped the op, you trying to show him up was pointless and only makes you look like a douchebag.[/QUOTE]And makes the op confused.
[QUOTE=Stonna;32691786]Or, "Man Whithout Hat" you could not be a noob and do _R.Player.SomeFunc( LocalPlayer() );[/QUOTE]
I'm no noob. I've been doing lua since you were 10 and a half. (Based on what you said your age was).
I told that guy the easier-to-understand method of doing it because he probably wouldn't understand the lua registry yet.
<snoip>
what exactly 'is' the lua registry? there's nothing on it
Lua registry is basically the lua call stack, and a collection of objects. The objects are stored there so as they can be referred to. It is also used for storing data between C and Lua.
[url]http://www.lua.org/manual/5.1/manual.html#3.5[/url]
Sorry, you need to Log In to post a reply to this thread.