How do I work touches for multiple different tasks?

I have a touch function which changes the sprite animation and has the character jump into the air, but I need to be able have him run and jump and attack using touch. If I create multi functions, it overrides the previous one. How can I create a function which allows me to change the action to pick which one and change his action?

below is the code for only the jump change animation

local function onTouch(event) – creates the even function
if(event.phase == “began”)then – if this then that
animate:setSequence(“jumping”) – when touched sets the animation to jumping animation
animate:setLinearVelocity(0,-200) – jump 200 upward
animate:play() --run the animation
elseif(event.phase == “ended”)then – when the touch end
animate:setSequence(“idle”) --return the character to his idle stance
animate:play()-- run idle stance
end
end

You have to think about jumping as well as landing.
Even if the jump starts with a touch event,
Landing can be triggered by enterFrame or other events such as timers or collisions.

It is worth referring to the game code created by Ponywolf.

Thank you, I’ll try to work my way into his coding and see if I can find how he does it.