Ohhh, I think I get what you mean.
That wonât work as the first argument inside of funcs.Function has to be self
(which is the function environment IIRC).
Using a colon for calling a function is called syntactical sugar.
So letâs use game:GetService(âWorkspaceâ) for example.
If we do game.GetService('Workspace')
, it doesnât work. It will return an error similar to âExpected . instead of :â
You are in fact able to bypass this by sending the function environment to the function (which in our case would be game).
game.GetService(game, 'Workspace') -- this works! We are sending what would be considered 'self' to the function.
So in our case, we would have to send the funcs table as the first argument to the function
local funcs = {}
function funcs.Function(self, arg)
print(arg)
self.variable = 'ok'
for i,v in pairs(self) do
print(i,v)
end
end
coroutine.wrap(funcs.Function)(funcs, 'Hello!')
--[[Output:
Hello! -- this is what is being printed. It is what was passed as the `arg` argument.
Function function: 0x55d4d37c4820
variable ok -- the variable we've assigned
]]
What this allows us to do now, is call that function with a colon.
funcs:Function('Hello!')
--[[Output:
Hello!
Function function: 0x55d4d37c4820
variable ok
]]
Basically a colon is telling the function that an invisible variable called self
exists inside of the function without having to manually declare it.
So how is this relevant in your case?
function funcs:Function(arg)
self.variable = 'ok'
print(self.variable)
end
coroutine.wrap(funcs.Function(funcs, 'Hello!')) -- You are able to do this
funcs:Function('Hello!') -- AND this.
And that is how you send a function using a colon (a method) as an argument.