Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Custom instances — Gideros Forum

Custom instances

totebototebo Member
edited January 2014 in Code snippets
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

My Gideros games: www.totebo.com

Comments

Sign In or Register to comment.