Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
error with linear manipulation of table elements — Gideros Forum

error with linear manipulation of table elements

HolonistHolonist Member
edited October 2014 in General questions
Hi guys, I have the following problem:

I have an object with a progress bar. Whenever the progress advances far enough, an additional square gets lit up.
--Initialization of 24 squares
--
self.bars = {}
local k = 0
for i=1,24 do
	self.bars[i] = Geom.createRectAngle(0,0,10,10,0x115578)
	self.bars[i]:setPosition(self.x+5+(i%6)*15, self.y+8+(k*15))
	self:addChild(self.bars[i])
	if i%6 == 0 then
		k = k+1
	end
end
--Colortransforming of all available squares in the ENTER_FRAME event.
--self.framesElapsed is reset to zero once the progress reaches 100%
--
local prog = round((self.framesElapsed/self.framesNeeded)*#self.bars, 0)
 
if prog > 0 then
	for i=1, prog do
		self.bars[i]:setColorTransform(2,2,2,1)
	end
else
	for i=1, #self.bars do
		self.bars[i]:setColorTransform(1,1,1,1)
	end
end
So far the mechanism works, but there is one bug.
Please have a look at my video I uploaded, you will get what I want to do and what's the problem:


The first square to be color transformed is always the SECOND one in a row.
To my understanding, it should be the first one, according to my code.

Instead, the first square in a row will be the last one which gets color transformed.
Is this some kind of special behaviour of lua I missed out on?

Thanks in advance

Comments

Sign In or Register to comment.