Hi guys, where am I going wrong here?
I'm trying to create two instances of "Ball" and print each ball's size afterwards. The output now is "big", "big", so the "size" variable is overwritten when I create the second instance.
Niclas
-- Ball.lua
Ball = Core.class()
local size
function Ball:init( _size )
size = _size
end
function Ball:getSize()
return size
end |
-- Main.lua
local balls = {}
local ball1 = Ball.new( "small" )
table.insert( balls, ball1 )
local ball2 = Ball.new( "big" )
table.insert( balls, ball2 )
for i=1, #balls do
print( balls[i]:getSize() )
end |
Comments
Likes: ar2rsawseen
But because it is impossible to delete a posy I edited it instead lol
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Edited a perfectly good post and put in a typo (
Likes: talis
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive