Mkaing a function using methods

Simple question; how do you create a function that gets an argument with a method? IE being able to pass it like [lua]x:F()[/lua] instead of like [lua]F(x)[/lua]

I’m pretty sure you do it just as you did with the first code snippet. You would then use self to access the argument.

I didn’t get any of that

Are you saying I can just do
[lua]
function x:F()
//doshitwithXhere
end
[/lua]
and be able to call my function like
[lua]
x:F()
[/lua]
?

Alright, say you have just created a variable. For these purposes I’m just going to make a table with a few strings.

[lua]local x = {“This”, “is”, “a”, “table”}[/lua]

Now you want to use this table and pass it to another function which has previously been created.

[lua]function x:F()
PrintTable(self)
end[/lua]

I’m not entirely sure if this what you’re asking at this point, but you could do something like x:F() and call the function passing x as the first argument.

EDIT: Yeah, you got to it before me. Yes, pretty much.

**[G.FindMetaTable

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.FindMetaTable)**

That works, danke schön

For the reference, you can use methods on any table or table based type.

[lua]local t = {}
function t:What()

end

local t = _R.Player

function t:What()

end[/lua]

Both are valid.

To avoid confusion: “_R.Player” is exactly the same as calling “FindMetaTable(‘Player’)”