Prevent multiple button presses with Director

Any help would be GREATLY appreciated! =)

We are working on a type of trivia app and have found that if users click the correct answer button multiple times very quickly, they can receive more than one correct answer. This results in a problem where users can score 17/10 if they get 2 or sometimes even 3 clicks on the correct answer before the scene changes.

Here is the code when the correct answer is clicked:

[lua]local function pressAnswer (event)
if event.phase == “ended” then
settings.rightNum = settings.rightNum + 1
print(“score incremented by 1”)
director:changeScene(“result”,“overFromTop”)
end
end[/lua]

SO… to prevent this “bug” of users clicking the right answer multiple times, we’ve added a check variable so the button can only be pressed once:

[lua]local function pressAnswer (event)
if event.phase == “ended” then
if (buttonsOn == true) then
settings.rightNum = settings.rightNum + 1
print(“score incremented by 1”)
director:changeScene(“result”,“overFromTop”)
print(“scene has changed”)
buttonsOn = false
print(“button has already been pressed once, and is now inactive”)
end
end
end[/lua]

Now the problem we are having when clicking on the button very quickly, is that the Director changeScene is not being run. The score will increment, all the print statements will show up in the terminal (the print statements before the director:changeScene line and the print statements after it all show up), but the scene doesn’t change.

I figured that the line of code MUST be running, since print statements before and after it are running, but it’s trying to run before Director is capable of handling it, and therefore nothing happens.

After looking into the director.lua file and adding in some print statements, I’ve discovered that in function director:changeScene there is a line of code that checks whether Director is already changing scene when a call to changeScene is made, and if so, Director will ignore this call to changeScene (since it’s already in the middle of performing a changeScene from an earlier call)

So the issue is that when we press the button real fast as soon as the scene loads, the buttonsOn variable is set to false as expected, but the call to switch scenes is ignored. Now users are stuck - the app should have switched scenes when they pushed the button. The switch didn’t happen because Director wasn’t ready for the call yet, and the button is now inactive because they’ve already pressed it once and we’re preventing them for pressing it multiple times. They’re still viewing the scene that they should already have moved on from, and they can’t press the button again because they’ve already pressed it once.

I commented out the check on “isChangingScene” in director.lua, but I still get to this state where the app won’t change scenes when trying to change them so quickly.

While the app works perfectly in every other way and we could submit it with the thought process that “users who are trying to bash all the buttons quickly deserve to have the app stop responding” we’d much rather find a fix so nobody can cheat the system with multiple button presses but also nobody gets stuck in an unresponsive screen of the app - but not sure that a fix is possible while using the Director class.

We may have to rewrite the app without the use of Director, simply having two “screens” existing in the same .lua file and turning the visibility off for one screen while turning the visibility on for the other. We do really like using Director though, so if there is some way to fix this issue that would be the best option.

The ‘result’ scene that we are switching to shows users whether they answered the question correctly or not, and then a button in that scene returns them to the original .lua file which asks them the next trivia question.

Looking forward to any great ideas from the great Corona community!
Thanks so much in advance!
[import]uid: 42083 topic_id: 29779 reply_id: 329779[/import]