A touch function is different than any other function?

Hello.

I have a function like this

   function playButton:touch( event )

    – // Here I have a lot of code

    end
    playButton:addEventListener( “touch”, playButton )

So when I “touch” the image playButton, this function works fine.


Later in the code I have another function

&nbsp;&nbsp;&nbsp; function repeatMusic() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;function count1() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print("1") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;c1 = timer.performWithDelay(tempo\*1, count1) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;function count2() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print("2") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;c2 = timer.performWithDelay(tempo\*2, count2) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;function count3() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print("3") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;c3 = timer.performWithDelay(tempo\*3, count3) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;function count4() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print("4") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;c4 = timer.performWithDelay(tempo\*4, count4) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;function count5() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print("5") &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; playButton:touch( event ) -- \<----- HERE IS THE PROBLEM! &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;c5 = timer.performWithDelay(tempo\*5, count5) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;repeatMusic()

And I want to “call” the playButton:touch( event ) function

but it’s not working.

How can I call that function?

do I need something different?

What am I missing?

thanks for your help

Victor

table “event” is passed form system, read here for all properties: http://docs.coronalabs.com/api/event/touch/index.html

Inside playButton function what properties of “event” you use? Maybe phase?

If you want call it you should pass “event” table, like this:

playButton:touch({phase="began"})

simonevalenti73 is right … the event types for a timer and a touch event are very different. 

From a software engineering perspective, you might want to lift the code that plays the sound (or whatever the “real work” is) out of both the touch and timer functions and make it it’s own thing … i.e. the playButton:touch handler calls function playMySound( ), and the count5 function also calls playMySound( ). 

I have never seen that before…

playButton:touch({phase=“began”})

But it works…Thanks!!!

I guess there are so many things to learn…

thank you very much for all your help

programming is really fun! (when you get no errors)

it gives you a chance to express your creativity.

thanks

Victor

table “event” is passed form system, read here for all properties: http://docs.coronalabs.com/api/event/touch/index.html

Inside playButton function what properties of “event” you use? Maybe phase?

If you want call it you should pass “event” table, like this:

playButton:touch({phase="began"})

simonevalenti73 is right … the event types for a timer and a touch event are very different. 

From a software engineering perspective, you might want to lift the code that plays the sound (or whatever the “real work” is) out of both the touch and timer functions and make it it’s own thing … i.e. the playButton:touch handler calls function playMySound( ), and the count5 function also calls playMySound( ). 

I have never seen that before…

playButton:touch({phase=“began”})

But it works…Thanks!!!

I guess there are so many things to learn…

thank you very much for all your help

programming is really fun! (when you get no errors)

it gives you a chance to express your creativity.

thanks

Victor