self is a keyword used to describe the corresponding object in object oriented programming. When used in a method, it refers to the object in which the method is being called on.
Self used int the first script would throw an error because self is not defined.
local something = {}
something.__index = something;
function something.new() -- Self is not defined in constructor functions.
local self = setmetatable({}, something};
self.somethingElse = 3123;
return self;
end
function something:printSomethingElse() --Self would be defined here since it's a method of "something"
print(self.somethingElse);
end
local somethingObject = something.new();
somethingobject:printSomethingElse(); --> 3123
Object oriented programming can be a little hard to understand for beginners, so I recommend reading up on it.