Function in table.

[lua]
okay = {}
function okay:Ok(str)
print(str)
end

okay.Ok(“hi”)
[/lua]

It says str is nil. What could i do to achieve what im trying to?
I thought about okay:Ok(“hi”) instrad, but cant test atm

Don’t confuse : and . around.

Defining the function with : means the first argument is hidden and is self, where self will be the “okay” table.

Calling okay.Ok with a dot (.) calls it like a normal function, “hi” will be the first argument ( self in the definition ) and the second argument is nil.


okay = {}
function okay:DoubleDot(str,str2)
    print(self, str,str2)
end
function okay.Dot(str,str2)
    print(self, str,str2)
end

okay.DoubleDot("hi")

// These two are equal
okay.DoubleDot(okay, "no")
okay:DoubleDot("no")

okay.Dot("hi2")
okay:Dot("hi2")


Try running this code and see the difference.