Posted 11 August 2012 - 12:10 AM
I am completely confused right now… This ran in a computer outputs NOTHING
But run it twice and it ouputs:
Also, if you duplicate this block of code and run it once
It outputs
WAT?
Is there something wrong with OOP in LUA or ComputerCraft?
Or am I doing something wrong?
I got the point 'class' from http://www.troublesh.../lua/luaoop.htm
point= {} -- THE CLASS
point.new = function(name, x, y)
-- #PRIVATE VARIABLES
local self = {} -- Object to return
name = name or "point"
x = x or 0 -- Default if nil
y = y or 0 -- Default if nil
-- #GETTERS
self.getname = function() return name end
self.getx = function() return x end
self.gety = function() return y end
-- #SETTERS
self.setname = function(arg) name = arg end
self.setx = function(arg) x = arg end
self.sety = function(arg) y = arg end
-- #DRAW
self.draw = function ()
print (name.." = "..x..","..y)
end
return self --VERY IMPORTANT, RETURN ALL THE METHODS!
end
derp = {pointA, pointB, pointC}
pointA= point.new("YES", 3, 4)
pointB= point.new("NO", 7, 8)
pointC= point.new("MAYBE", 8, 9)
for i = 1, #derp do
derp[i].draw()
end
But run it twice and it ouputs:
YES = 3,4
NO = 7,8
MAYBE = 8,9
Also, if you duplicate this block of code and run it once
derp = {pointA, pointB, pointC}
pointA= point.new("YES", 3, 4)
pointB= point.new("NO", 7, 8)
pointC= point.new("MAYBE", 8, 9)
It outputs
YES = 3,4
NO = 7,8
MAYBE = 8,9
WAT?
Is there something wrong with OOP in LUA or ComputerCraft?
Or am I doing something wrong?
I got the point 'class' from http://www.troublesh.../lua/luaoop.htm