I was reading and saw that he mentioned that when you add a Colon when calling a function from an inside constructor table, the table gets passed into the parameters, which allows changing a true/false value declared inside the table. what’s the difference between using a period and why does it not work with one? I find my biggest weakness in coding is understanding truly why things are the way they are.
Sorry, that was misleading. What I’m understanding from this is that when I call the function in the table using a colon, I’m essentially passing the table into the function , and if I use a period this would not work?
As @kingschool9 mentioned, calling a function with : passes self which is a variable that redirects itself to the table that you called it from. Calling functions from a dot(.) directly indexes the function. It’s recommended to only use the colon when you need the self argument
Example:
local tbl = {} -- the main table
tbl.var1 = 0 -- first property
tbl.var2 = 9 -- second property
function tbl:_add() -- method
return self.var1 + self.var2 -- uses "self" to index the table so you can access the properties of it
end
function tbl.add(arg1, arg2) -- function
return arg1 + arg2 -- return "arg1 + arg2"
end
print(tbl:_add()) -- prints "9"
print(tbl.add(7, 8)) -- prints "15"