how to prevent a double tap

‘Sample code with sample app’
I do not know of you are aware but with Corona you install a lot of sample apps with sample code. When you open corona simulator then there is always window with black background and few buttons. Under one of them (if you click it) there is bunch of samples divided into tematic sections you can browse to learn.

‘Little videos’
There is a lot of videos on internet. On youtube CoronaLabs has even it’s own training videos.

‘Make it difficult…, make it on purpose…’
I think you are wrong here. They nowhere make things difficult on purpose, no one does - for what purpose they would?
Things are written straightly and in minimalistic yet essential form. However, it’s hard not to write about things without using terminology associated with them. These are english words for sure (think that people around the world must know english to get access to documentations and the bigger sources of knowledge). If you talk about music you also use music terms and there is nothing wrong with it - one cannot blame this terms because he cannot comprehend them. You just have to somehow get your head around it and slowly learn.
If you would like to have everything in documentation written with smallest details and explained throughly then there is no sense, meaning that you always have to assume that people have some knowledge or will slowly get it. I have nowhere seen documentation written more then essential. It’s aim of samples and tutorials to explain things more.

@piorz55 - I agree.

In reference to this “This is very difficult to achieve using the
default dispatch behavior and propagation rules of hit events.”
They
are not referring to the entire process of creating an event. Notice
they are talking about " Overriding Propagation with focus" and how
using the default method would be difficult.
If you don’t know what ‘Propagation’ is then google it :smiley:

“in plain English words, not computer terms.” This is programming, therefore there will be program specific terms. That’s why the docs are there, to demonstrate and explain how to apply them.
lol As a jazz pianist, I’ve had friends tell me the same thing - “Why not just speak English?!”
diatonic scale, deceptive cadence, glissando etc… Everything takes time to learn, music theory being an excellent example.

 

“do they do it like that to make it on purpose difficult, so only a very few privileged ones can actually make nice apps?”
lol no. Lua is a very beginner friendly language. :slight_smile:
The people you refer to as “privileged” are creating “nice apps” because they took the time needed to learn all this so they know how to apply it to their own app/s. They did not limit themselves by thinking only certain people are able to learn this.
I never had people giving me all the answers&code whenever I had a problem, that’s not to say I haven’t used the forums of course I have.
However, because I took the time to learn the inner-workings and mechanics behind the code I am now able to create my own mildly complex functions and understand how to manipulate other code I find, to suit my own needs.
Am I an expert? HAha not even remotely. I’m still a newb when it comes to all this. :wink:

As far as getting the code from piotrz55, event.other.name
If you read the docs you’d understand what ’ event’ ’ other’ and ’ name’ are referring to and therefore would’ve been able to do it yourself.
Like I’ve said before, it’s one thing to paste in event.other.name and see the result, but it’s another thing to understand why you’re using that syntax.
I can almost guarantee piotrz55 did not magically know what that syntax means and how to use it.
He, as well as most other people, took the time to learn what it all means.

Also, “or they just don’t have time and money to add videos graphics, pictures, sample code, and all that to their web-site?”
I very highly doubt it. They aren’t any shortcuts when it comes to learning programming.
The majority of their docs are organized well and easy to understand if you take the time.

* While lua is an easy language to learn with, there are basic/fundamental concepts that are universal across all programming. It’d be good to learn them. :slight_smile:

ANYWAYS, it seems develephant is willing to jut give you the code, with that said I end my “speech/rant”.
Btw, I say all this to motivate you Not get ya down. :slight_smile:

-Saer

Edit: My all time favorite quote is "The only limits in life are those we set ourselves. "
:slight_smile:

Events are a higher level bit of programming.  They are so simplistic that they come off complicated, and really don’t make much sense until you “get it” in my opinion.

I’ve been programming for over 20+ years.  I’ve also taught quite a few classes, and I know a lot of developers frown upon giving out code.  But it’s been my experience that sometimes just getting over certain bumps in the road can be very energizing.  When a person is frustrated,  it’s hard to problem solve.  I can see that he is obviously bright enough to get to where he is now.  In my opinion, giving a tiny piece to the bigger picture is not going to spoil his learning experience.

Cheers.

Thank you develephant. I just need a little bit.

it works!!! really good!!!


But you know what…

Yesterday, my brother came from Mexico, to visit me for my Birthday.

I have not seem him in long time(for personal reasons)

he is en Engineer an a Programmer, he’s been programming for

over 25 years, he is really good at that.


I show him what I was doing…it’s like Mary had a little lamb for him, like kindergarten.

He makes huge programs for companies.


He told me the same things you are talking about. an I understand you now a little bit better.

I just want to do things faster.

I study music for 10 years, and I have been in music for 30, so I do know music really well.

I just need time(but sense I’m 53) I don’t know how much time left I have.

that is not your fault.

I’m going to keep reading, and learning, and making apps.


anyway, I had a problem for 6 months in an app

I told the problem to my brother, and in 20 minutes

he wrote a function and told me how to do it.

like nothing, simple for him.


he mention a lot of “passing” something to a function

or the “return” this or that

terms I just don’t get it well, but he help me to try to understand that.


I understand you better, much better now, thanks for everything

you have help me a lot. and I know what I know thanks to you…

I have writen before: if you want to play it once then remember that its playing

Just a note: the “numTaps” event value can also filter this down to the first tap only. But as @piotrz55 says, you should also check that the song is not already playing.

http://docs.coronalabs.com/api/event/tap/numTaps.html

Brent

Hi piotrz55.

I tried this

– if tapAlreadyDone == false then

end

and inside I put the function – no good.

I tried putting it in different places – no good

I know that you might have told me something similar before

but I still don’t understand it very well. Sorry, I am not as good as I should be.

I’m doing my best


Hi Brent. I read the page for numTaps

I did not understand it. I didn’t know how to apply it to my problem.


and when you said

“you should also check that the song is not already playing.”

how do I do that?

Hello, ‘i tried putting it in different places’ -stop there! Programing is not a magic trick, it’s strict and based on logical concepts tool to archive certain task. When programing you must be like engineer with screw driver. You know or not how to use it. If not you can try and learn but plisss… do not except it to work somehow when you put it everywhere you can blindly.

I know learning programing is hard and not always easy to catch. I understed making errors and learning. But, for your own good, do not: put it everywhere and wait something happened. I am aware you are rather humanist typs (music) but please be aware of it otherwhise you will hurt yourself and create needles mess and confusion.

Treat programing like building from lego blocks. There are always basic and constant components. There are many ways to connect but you won’t make good structures trying to connect them without obeying their properties.

Also you need to think flexible. For example we give you screw driver and you learn how to use but it doesn’t mean you use it for everything as is. You must sometimes change something, make useful for you - as to use hammrer for other problem and screw driver for other.

Ask - we will always try to help you but there are some things we can’t - you must overcome it yourself and we will try to guide you

As for posting for code: we won’t know the music if you only give us some parts of notes or say you play it high when we have no idea what you play. Always give us some code around asked parts not random notes.

Hi piotrz55, thanks for all your advices.

I liked when you said “You know or not how to use it.”

well, I guess I don’t know yet!

I’m learning, and thanks to all your advices and every one else

I doing some apps. I really like to learn all this, it’s wonderful.

But I do need a lot more help.

When I try something new, I have a little idea in what to do.

but I know that I do need a lot more.

this is the code

newImage = display.newImage ("start.png")     group:insert ( newImage )     newImage.x = 280; newImage.y = 500         local function pennyTap ()             local function playSong ()                 audio.play(pennySong)             end                     transition.to(ImageLarge, {time=200, x=465, y=756, alpha=1, onComplete=playSong})         end     newImage:addEventListener("tap", pennyTap)

very simple, but in double tap or even triple tap I hear 3 songs right after the other like echo

And believe me, I do honestly appreciate all the help you guys give me here.

if it wasn’t for you I would never be able to make the apps and work on this

it will take me time to learn, but I will, and I will share everything I know with

more people, I think programming it’s a wonderful art.

As stated in the docs,
event.numTaps - “The number of taps on the screen.”

i.w. you can get the current number of taps and use that for deciding whether or not something should happen; in your case playing an audio file.

Or if you don’t want to do it that way, you could simply create a variable “numTaps” (or whatever you want to name it) set it to zero and then when the object (you’re listening for) is tapped just increase ‘numTaps’ value by one. That way you can tell it Not to play the song if ‘numTaps’ equals a certain value - 2,3,4 etc…

Cheers!

-Saer

I know that you guys want me to think.

and that is good…

but today all day long I have thinking and thinking

and I just can’t.

maybe tomorrow…

I did this

local numTaps = 0 local songIsPlaying = false

and then this

local function play ()                 if numTaps == 0 then                     songIsPlaying = true                     songIsPlaying = audio.play(pennySong)                     numTaps = numTaps + 1                 elseif numTaps \> 0 then                     print("no song")                 end             end  

and no good.

there are so many ways of doing it

but I just can’t find one of them.

if you guys don’t want to actually write this piece of code

I will understand, you’re trying to help me to actually “think”

I’m just not that good yet.

Firstly, in your code you are telling the song to play if numTaps = 0 and then in the same conditional statement you’re increasing ‘numTaps’… so technically you’re not doing anything differently.

‘numTaps’ is just a way you can manually keep track of a value.
For example, say you had a bunch of cars moving throughout the display and you wanted something to happen when the current number of cars equaled 20.
Just create a variable - numCars = 0
Then every time you add a car to the screen/display you would increase it - numCars = numCars + 1

 - I’ll use your own code -

local numTaps = 0 local function play ()     if numTaps == 0 then        songIsPlaying = true        songIsPlaying = audio.play(pennySong)        numTaps = numTaps + 1      elseif numTaps \> 0 then          print("no song")     end end

What you’d need to do is increase ‘numTaps’ by one when you touch/tap the penny.

local numTaps = 0 local function play ()   -- increase 'numTaps' by one --      -- then if 'numTaps' equals 1 play the song -- -- other code here --      elseif numTaps \> 1 then          print("no song")     end end

Since you’re using ‘numTaps’ on a conditional basis, you’ll have to decrease its value after the event has completed - If you didn’t, the song would never play because every time you tap the penny ‘numTaps’ would keep getting increased.
I would consider either making your function an event so that on the ended phase of the tap you can decrease the value of ‘numTaps’ by one or make your ‘penny’ object a widget-button and then code what you want to occur in a function that you would reference in the ‘onRelease’ call.

-Saer

Thank you Saer…

on double click the – the first time –

works great I don’t hear 2 songs.

but I when I click the second time – I hear Nothing.

it works only once.

--------- today that’s it------ my brain is stuck!

I’m going to keep working on this tomorrow

I can try the widget-button option to see if I can make it work.


the other problem is the yellow rects…

I stop the music but the rects keep showing on/off

I will try to see if I can apply the same logic on the done button.

thanks for all your help guys.

I’m going to keep working and learning

if there is someone that never gives up… it’s me.

thanks

Are you reducing ‘numTaps’ value by 1 after the event has finished?
Like I said above “Since you’re using ‘numTaps’ on a conditional basis, you’ll have to decrease its value after the event has completed”
When you tap the penny ‘numTaps’ gets a 1 added to its current value, if it’s the first tap then it would be 0 + 1 making its current value 1, then if you go and try to play the song again you’d find, as you have, that it won’t play… that is because you never reduced ‘numTaps’ which means every subsequent tap is increasing the value (first tap sets the value to 1, second to 2 etc… etc…)
Obviously your song won’t play because you have
elseif numTaps > 1 then
  --don’t play the song–

Simply decrease ‘numTaps’ after the event/function has ended.

-Saer

I did this

local function play ()                 numTaps = numTaps + 1                 if numTaps == 1 then                     songIsPlaying = true                     songIsPlaying = audio.play(pennySong)                     numTaps = numTaps + 1                 elseif numTaps \> 1 then                     print("no song")                     numTaps = 0                 end         end  

I think that is what you said about – “Simply decrease ‘numTaps’ after the event/function has ended.”

but now weird things happens.

– if I play once fine – the first time

– I push the button done once

– I play again – no sound

– I push the button done

–Push play and it plays the song

done

play – nothing

done

play – yes


one yes and one no

— and also the yellow rects, they keep visible = true and false

here is the complete code if you please can get me out of this misery

I think is way too much for me at this point

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require "widget" ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[LOAD SOUNDS]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local pennySong = audio.loadSound ( "penny.mp3" ) ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[VARIABLES]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local pennyImage local pennyImageLarge local done local measure1 local numTaps = 0 local songIsPlaying = false local distance = 245 local measure1Timer local measure2Timer local measure3Timer local measure4Timer local measure5Timer ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[FUNCTIONS]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ local function yellow1 ()     local function measure1Listener( event )         measure1.isVisible = true     end     measure1Timer = timer.performWithDelay( 200, measure1Listener ) end local function yellow2 ()         local function measure2Listener( event )         measure1.isVisible = false         measure2.isVisible = true     end     measure2Timer = timer.performWithDelay(3130, measure2Listener ) end local function yellow3 ()         local function measure3Listener( event )         measure2.isVisible = false         measure3.isVisible = true     end     measure3Timer = timer.performWithDelay(6260, measure3Listener ) end local function yellow4 ()         local function measure4Listener( event )         measure3.isVisible = false         measure4.isVisible = true     end     measure4Timer = timer.performWithDelay(9390, measure4Listener ) end local function yellow5 ()         local function measure5Listener( event )         measure4.isVisible = false         measure5.isVisible = true     end     measure5Timer = timer.performWithDelay(12400, measure5Listener ) end ---------------------------------------------------------------WIDGET FUNCTION------------ local function pennyImageHandler()         local function play ()                 numTaps = numTaps + 1                 if numTaps == 1 then                     songIsPlaying = true                     songIsPlaying = audio.play(pennySong)                     numTaps = numTaps + 1                 elseif numTaps \> 1 then                     print("no song")                     numTaps = 0                 end         end             transition.to(pennyImageLarge, {time=200, x=display.contentWidth / 2, y=display.contentHeight / 2, xScale=1, yScale=1, alpha=1, onComplete=play})         transition.to(done, {time=200, y=700})         yellow1()         yellow2()         yellow3()         yellow4()         yellow5()         return true end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event )     local group = self.view     local background = display.newImage ("backgroundBook.png")     group:insert ( background )     pennyImage = widget.newButton{         defaultFile="pennyImage.png",         onRelease = pennyImageHandler     }     group:insert ( pennyImage )     pennyImage.x = 280; pennyImage.y = 500          local tx1 = display.newText("The song for piano is just an example so I can make this beautiful book, and I know that once I finish this. I will be doing okay. Corect!. Now I can type more text. And then I can play more songs, I just want to see if I can make it work", 0, 0, 440, 200, native.systemFont, 16)     group:insert ( tx1 )     tx1.x = 290; tx1.y = 170     tx1:setTextColor(0, 0, 0)          pennyImageLarge = display.newImage ("penny.png")     group:insert ( pennyImageLarge )     pennyImageLarge.x = pennyImage.x; pennyImageLarge.y = pennyImage.y     pennyImageLarge.xScale = .1     pennyImageLarge.yScale = .1     pennyImageLarge.alpha=0          done = display.newImage ("done1.png")     group:insert ( done )     done.x = display.contentWidth / 2; done.y = 900         local function doneStop ()             audio.stop()             transition.to(done, {time=200, y=900})             transition.to(pennyImageLarge, {time=200, x=pennyImage.x, y=pennyImage.y, xScale=.1, yScale=.1, alpha=0})             measure1.isVisible = false             measure2.isVisible = false             measure3.isVisible = false             measure4.isVisible = false             measure5.isVisible = false             timer.cancel(measure1Timer)             timer.cancel(measure2Timer)             timer.cancel(measure3Timer)             timer.cancel(measure4Timer)             timer.cancel(measure5Timer)         end     done:addEventListener("tap", doneStop)          musicList = display.newImage ("buttonMusic.png")     group:insert ( musicList )     musicList.x = 100; musicList.y = 730         local function listListener ()             storyboard.gotoScene( "page2", "fromRight", 100 )             audio.stop()             timer.cancel(measure1Timer)             timer.cancel(measure2Timer)             timer.cancel(measure3Timer)             timer.cancel(measure4Timer)             timer.cancel(measure5Timer)         end     musicList:addEventListener("tap", listListener) end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[ENTER SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:enterScene( event )     local group = self.view          measure1 = display.newRect(0, 0, 160, 106)     group:insert ( measure1 )     measure1.x = distance; measure1.y = 305     measure1:setFillColor(255, 255, 0)     measure1.alpha = .2     measure1.isVisible = false          measure2 = display.newRect(0, 0, 166, 106)     group:insert ( measure2 )     measure2.x = distance \* 1.66; measure2.y = 305     measure2:setFillColor(255, 255, 0)     measure2.alpha = .2     measure2.isVisible = false          measure3 = display.newRect(0, 0, 161, 106)     group:insert ( measure3 )     measure3.x = distance \* 2.345; measure3.y = 305     measure3:setFillColor(255, 255, 0)     measure3.alpha = .2     measure3.isVisible = false          measure4 = display.newRect(0, 0, 164, 106)     group:insert ( measure4 )     measure4.x = distance \* 3.02; measure4.y = 305     measure4:setFillColor(255, 255, 0)     measure4.alpha = .2     measure4.isVisible = false          measure5 = display.newRect(0, 0, 160, 106)     group:insert ( measure5 )     measure5.x = distance \* 3.7; measure5.y = 305     measure5:setFillColor(255, 255, 0)     measure5.alpha = .2     measure5.isVisible = false end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[EXIT SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:exitScene()      end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:destroyScene( event )     local group = self.view                  end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

Thanks you for everything

my wife it’s waiting for me outside

see you tomorrow

thanks

The reason it doesn’t sometimes works is because of the following:
First tap numTaps = 1 – plays song – > second tap numTaps = 2 – does not play song – numTaps is greater than 1 set to 0 > third tap numTaps = 1 – plays song – Etc… etc…

What you need to do, is make this whole thing an event and on the ‘ended’ phase reduce numTaps by 1.

-Saer

I really don’t know how to make this in to an event

would you please show me the code to make it into an event?

I know I should think or try to do it on my own, but honestly

it’s too much. You will show me and teach me a lot

if you can actually show me the actual code.

Thanks for everything.