I have been confused with “self” in lua and have never used it.
What is “self” and an example on how i could use it?
I have been confused with “self” in lua and have never used it.
What is “self” and an example on how i could use it?
I personally use self
as a table name, mainly for a module. Something like this:
local self = {};
self.Get = function()
return false
end
return self;
I am not sure if that’s the best use of it, but that’s personally how I use it.
To my understanding its only really used in Module scripts. Self is a whole discussion on Object Oriented Programming but basically self is used to reference an object within its own code. Thats a simple way of putting it. Im not sure how much you understand about object oriented programming but if you dont know anything about OOP, its probably something you should take your time learning at a smooth pace.
This should help you:
Thank you! This showed me more and im starting to know it!
self is like a variable which can be set to many things.
Like people already mentioned it’s mainly used in OOP but basically it’s just a shortcut to access an object’s table (data). There’s a few more instances you could use it for but this is the most useful case.