Hey guys, I’m new to this program, I’m getting stressed out because I can not understand where is my mistake. To make it easy for you guys, I created some sprites, I press the button to do the action, but the character does his animation in infinite loop and only stops when I press the same button again. I would like some code suggestion so I can press the button and the animation happens only as long as I hold the button and the character stops when I release the button. .
here is the piece of the code :
function on_input(self, action_id, action)
if action_id == hash("go_right") and action.repeated == true then
if self.currentAnimation == 1 then
msg.post("#sprite","play_animation", {id = hash("run_right")})
self.currentAnimation = 0
else
msg.post("#sprite","play_animation", {id = hash("idle")})
self.currentAnimation = 1
end
elseif action_id == hash("go_left") and action.repeated == true then
if self.currentAnimation == 1 then
msg.post("#sprite","play_animation", {id = hash("run_left")})
self.currentAnimation = 0
else
msg.post("#sprite","play_animation", {id = hash("idle")})
self.currentAnimation = 1
end
return true -- input handled.
end
end
please help me as soon as possible!