The title explains all, I'm confused with the usage of "this".
The difference of "this" and "script"?
1 answer
this
this is a keyword in most Object-Oriented Programming (OOP) contexts. It refers to the individual instance object of a class. Lua actually has a version of this feature, called self which works in the exact same way (Lua isn't an OOP language, but it is designed to support OOP concepts). For example...
-- Dog class
local Dog = {}
-- Method of Dog class: bark
function Dog:bark()
-- Increment number of barks within dog instance
self.barks = self.barks + 1
-- ...
end
In Lua, this is not a keyword. Rather, it's just an ordinary variable name. Someone may call a variable this if they're lazy, if the name of the variable doesn't matter, or perhaps if they're trying to emulate an OOP concept to make it look more familiar or conventional.
script
script is a keyword in ROBLOX's version of Lua. It refers to the actual script object in the game that the code is running inside of. For example, if you have your explorer window open with a script somewhere in your game, with this code inside of it:
script:Destroy()
...and you run this code, you will promptly see the script object in your game disappear. The script keyword is usually just used to access descendants or children that may exist in that directory.
6 comments
not a keyword. Keywords would be nil, for, break, etc etc
are you kidding me scriptguider i was writing a response before you even got to this page i hate you so much
It's debateable what the strict definition of "keyword" is, and by extension whether or not script is a keyword or just a built-in variable or whatever, but to argue this point is splitting hairs.
@MCAndRobloxUnited, that's just wrong. this exists in many other languages too, including JavaScript, C# and C++.
The definition of "keyword" is unambiguous; they are reserved words that cannot be used as identifiers. The keywords in Roblox's Lua are the same as those in Lua 5: and, break, do, else, elseif, end, false, for, function, if, in, local, nil, not, or, repeat, return, then, true, until, and while.
I personally just think about keywords as words that you shouldn't use as identifiers. The "true" definition may put emphasis on which you CAN'T use, but I find that it's good practice to group what you CAN'T do and what you SHOULDN'T do as the same thing.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
While 'this' may mean something in OOP in other programming languages, 'this' doesn't mean anything in Lua.
Oh so they are the same
You can read this wikipedia article https://en.wikipedia.org/wiki/Object-oriented_programming