Hi, I have a problem using enterframe.
I’m doing a game like the Timberman and I’m trying to add a feature but I don’t know how to do it.
The game has the same objective as the original game, try to cut as much tree as possible without hit any branch, while a bar decreases. If the bar decreases to zero or the player hit a branch then die.
I want to create a branch with a nest, that if the branch is cut before 3 seconds, the player fails and die. The problem is that when the player is going to cut the branch with the nest the event activates infinite times until the payer cuts the tree or corona crashes.
How can I activate an event that after 3 seconds the player can cut the the tree but only once?
That’s the code:
function character:chopWood(side) if self.sequence == "idle" and not self.dead then if side == 1 then self.xScale = 1; self.x = centerX+offsetX; else self.xScale = -1; self.x = centerX-offsetX; end self.mustChop = true; self:setSequence("chop"); self:play(); end end function character:enterFrame() if not self or not self.x then Runtime:removeEventListener("enterFrame", self); return; end if self.sequence == "chop" then if not self.isPlaying then self:setSequence("idle"); self:play(); else if self.frame == 3 and self.mustChop and not self.dead then self.mustChop = false; if currentActiveTreePart then audio.play(chopSFX, {channel = audio.findFreeChannel()}); currentScore = currentScore+1; currentRedBarJuice = currentRedBarJuice+redBarIncreaseStep; currentActiveTreePart:getChop(self.xScale); end end end end --HARD MODE-- if gameStart and currentActiveTreePart.branch.isVisible and not self.dead then if hardMode==false then if currentActiveTreePart.branch.isNest == true then print("In the nest") -- \<----THAT'S THE PART IT REPEATS INFINITELY end if currentActiveTreePart.branch.xScale == self.xScale then activateGameOver(); end else if currentActiveTreePart.branch.xScale ~= self.xScale then activateGameOver(); end end end if self.dead then self.alpha = self.alpha-0.05; self.deadStone.alpha = self.deadStone.alpha+0.06; for i = 1, 4 do self.smoke[i].alpha = self.smoke[i].alpha+self.smoke[i].alphaDir; self.smoke[i].x = self.smoke[i].x+self.smoke[i].xDir; self.smoke[i].y = self.smoke[i].y+self.smoke[i].yDir; self.smoke[i].xScale = self.smoke[i].xScale+.02; self.smoke[i].yScale = self.smoke[i].xScale; if self.smoke[i].alpha \>= 1 then self.smoke[i].alphaDir = -.02; end end end end Runtime:addEventListener("enterFrame", character);