what does "this" mean
I was looking through projects and I saw a lot of the word this being reused and I was wondering what it was cause I've never used it, I tried looking for it in documentation and didn't find it.
I was looking through projects and I saw a lot of the word this being reused and I was wondering what it was cause I've never used it, I tried looking for it in documentation and didn't find it.
'This' is usually used in classes.
Whenever you create a new object it will turn 'this' into the name of the object.
For example if the object name is blob1 then 'this.x' will now be 'blob1.x'
example:
blob = class
constructor = function(x,y)
this.x = x //<---- See this.x
this.y = y
end
follow = function()
screen.fillRect(this.x,this.y,20,20,"rgb(0,255,0)")
for i=1 to 10
if mouse.x > this.x then
this.x = this.x + 1
elsif mouse.x < this.x then
this.x = this.x - 1
end
if mouse.y > this.y then
this.y = this.y + 1
elsif mouse.y < this.y then
this.y = this.y - 1
end
end
end
display = function()
screen.fillRect(this.x,this.y,20,20,"rgb(0,255,0)")
end
end