so i've been ticking with the self keyword in lua,
I am assuming that the self keyword works very much like the this keyword in javascript, but i guess i could be wrong, since whenever I try to index a value from it, lua throws an error
tha's like this
attempt to index global 'self' (a nil value)
and here is my code;
local account = {
name ="Roblox",
sonsName = self.name.." jr", --error?
get = function()
return self.name --error?
end
}
print(account.get())
I tried making a closure to see if it'll get rid of the global part in the error,
but it's no use:
here is the code
local account = (function()
local account = {
name ="Roblox",
sonsName = self.name.." jr", --attempt to index 'self' a nil value
get = function()
return self.name --attempt to index 'self' a nil value
end
}
return account
end)()
print(account.get())

2 comments
ohhhhh, so calling a method on a constructor with the colon operator automatically passes the factory of that method as first argument to the method right?
btw, i am not in roblox.. i am running the code in command line..