function isn't being called

Hi

I have the following function in my flashcard app. Each time the user presses “next” to go to the next question, this is called. It checks to see if there are still cards to display or if we’re done. If we’re done, it calls the final display screen that shows the results. The weird thing is that the  call to the function that updates the json file that records the score usually gets ignored and is almost always not called. Also I threw in a print statement and that generally never gets called either. Not sure what’s going on …

continueToNextCardOrQuit = function(event)&nbsp; if ( event.phase == "began" ) then &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;display.getCurrentStage():setFocus(event.target) &nbsp; &nbsp; &nbsp;event.target:setFillColor(.87,0, 0,.3) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif ( event.phase == "ended" ) then &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus(nil) myData.displayAnswerCardGroup:removeSelf() myData.displayAnswerCardGroup = nil &nbsp; &nbsp; if ((myData.questionsAnswered + myData.questionsIgnored) \< #myData.questions) then -- there are still cards to display &nbsp; displayCard() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else -- game is over &nbsp; &nbsp; updateScoreFile() -- this function isn't called here so I have to call it -- from a different function (where it works fine) &nbsp; &nbsp; print("this doesn't print") -- and this doesn't print either &nbsp; &nbsp; displayFinalScreen() -- but this function DOES get called. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end return true end -- end of continueToNextCardOrQuit()

thanks,

David

Looks like the questions answered and the questions ignored are never going above the number of questions (obviously :)). Are you sure you’re incrementing them? Have you printed the value of them at the top of that function?

  • C

Hi

Yup they are incremented elsewhere. After the last card is viewed, questionsAnwered + questionsIgnored equals the length of questions, and so the “else” is triggered and displayFinalScreen() is called. That much works.  What’s weird is why other function calls in the same block are not happening. One time I got that print statement to fire off by putting a semicolon after it but that isn’t supposed to matter in lua.

thanks.

as described, only a “compile bug” could do that - if the block is executed at all, then the entire block should be executed (not just the last line).

how about commenting out everything except two print statements:

if ((qa+qi)\<#q) then -- paraphrased print("true block executed") else print("false block executed") end

are you SURE you don’t (accidentally) have two functions named “continueToNextCardOrQuit” and you’re working on the “wrong one”? or maybe you (accidentally) set up the listener to some other nearly-the-same-but-not-quite function? maybe add one more print at the very top, first line of listener, like: print(“i am where i expect i am”)

fwiw, hth

You are right. There’s another function doing something rather similar elsewhere. I will  see if refactoring is in order. Thanks for the help.

Looks like the questions answered and the questions ignored are never going above the number of questions (obviously :)). Are you sure you’re incrementing them? Have you printed the value of them at the top of that function?

  • C

Hi

Yup they are incremented elsewhere. After the last card is viewed, questionsAnwered + questionsIgnored equals the length of questions, and so the “else” is triggered and displayFinalScreen() is called. That much works.  What’s weird is why other function calls in the same block are not happening. One time I got that print statement to fire off by putting a semicolon after it but that isn’t supposed to matter in lua.

thanks.

as described, only a “compile bug” could do that - if the block is executed at all, then the entire block should be executed (not just the last line).

how about commenting out everything except two print statements:

if ((qa+qi)\<#q) then -- paraphrased print("true block executed") else print("false block executed") end

are you SURE you don’t (accidentally) have two functions named “continueToNextCardOrQuit” and you’re working on the “wrong one”? or maybe you (accidentally) set up the listener to some other nearly-the-same-but-not-quite function? maybe add one more print at the very top, first line of listener, like: print(“i am where i expect i am”)

fwiw, hth

You are right. There’s another function doing something rather similar elsewhere. I will  see if refactoring is in order. Thanks for the help.