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