Hello everyone, I am having some trouble implementing a simple flash-like effect I created for my health bar.
You see, the code for my health bar’s implementation, the health bar itself, and the health bar’s updating are all in different files hence making this very difficult.
--healthbar.lua (actual healthbar creation) function M.update() transition.to(myCurrentHealthBar, {alpha = 1, time = 500}) transition.to(myCurrentHealthBar, {alpha = 0.5, time = 1000, delay = 500}) end --asteroid.lua (healthbar updating) asteroidCollision = function(self, event) local other = event.other local phase = event.phase local mRand = math.random if phase == "began" then if other.id == "bullet" or other.type == "ship" then if other.canBeHit then other.health = other.health - self.damage other.healthbar.update() end self.health = self.health - other.damage if (self.health \<= 0) then explosion.new(self.parent, self.x, self.y, 1, 1, mRand(-10, 10), mRand(-10, 10)) display.remove(self) end end end end --ship.lua ship.healthbar = healthbar.new(group, ship)
Currently, when I run this code a get a nil value error, which I was sort of expecting. I thought about returning the components of the health bar but since there are more than one I can’t return them both. Any help would be great, thanks!