Adding "Else" to Event Listener ("if mouse ISN'T down")? Also, Reading What Sequence A Sprite Is Playing?

can you add an “else” to an event listener/function? e.g. i have a function/listener for when the screen is being touched. how can i run some alternative commands for when the screen isn’t being touched? e.g. when it’s being touched, abc = 1. when it’s not, abc = 0. i know you can use event.phase == “finished” for touch events, but maybe for things like whether a certain key is or isn’t held down?

also: can you check the current animation sequence a sprite is playing? as apparently setting a sequence re-triggers it (freezing you on the first frame), so you’d only want to if the sequence isn’t already playing. (turns out it’s guy.sequence)

e.g. if mouse is held down, and the sequence isn’t already flapping, set it to flapping. if mouse isn’t held down, and the sequence is currently flapping, set it to idle.

thanks!

(originally had a different question here but have solved it)

Look up enterFrame listeners. Basically this is an event that fires every frame update (30 times per second or 60 times per second). It can call a function repeatedly. In there you can use your touch function to set a flag when the touch event is on going and clear the flag when the touch is over. Your enterFrame function can react to that flag being set or not set.

See:

https://coronalabs.com/blog/2014/02/04/tutorial-continuous-actions-in-corona/

Rob

so at the start of every frame, set a check to false but change it to true if a listener goes off. that makes a lot of sense actually, thanks

I was wondering how you’d place an enterframe within a certain scene through the composer API. would it be within start scene, phase === did? or separately from all this, just within the scene’s file? thanks again

Normally there are placed in scene:show(phase == “did”) and remove in scene:hide(phase == “will”)

Look up enterFrame listeners. Basically this is an event that fires every frame update (30 times per second or 60 times per second). It can call a function repeatedly. In there you can use your touch function to set a flag when the touch event is on going and clear the flag when the touch is over. Your enterFrame function can react to that flag being set or not set.

See:

https://coronalabs.com/blog/2014/02/04/tutorial-continuous-actions-in-corona/

Rob

so at the start of every frame, set a check to false but change it to true if a listener goes off. that makes a lot of sense actually, thanks

I was wondering how you’d place an enterframe within a certain scene through the composer API. would it be within start scene, phase === did? or separately from all this, just within the scene’s file? thanks again

Normally there are placed in scene:show(phase == “did”) and remove in scene:hide(phase == “will”)