bug - program SOMETIMES skips score display screen

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

bug - program SOMETIMES skips score display screen

Post by randy0428 »

Hello,
I have a bug in a game I’m working on. I’ve attached the lua file which contains the game.

The purpose of this game/test is to test the players knowledge of the English present tense. It does this by presenting “questions” which consist of four sentences, only one of which is grammatically correct. The player has to choose which sentence is correct.

Sequence of the game:
1. The game starts (game state: splash) with a splash screen with a box to click on to start the game.
2. Clicking the box changes the game state to jogar (play) and the screen shows the first “question”, selected randomly from the list of 80 questions in the file data.lua. Additionally, the order of the four sentences in the question are randomized.
3. When the player clicks on the button of one of the sentences, the program checks to see if it is correct. If it is correct, the game state changes to cliqueCerto. If it is wrong, the game state changes to cliqueErrado. At this point the scoreboard is updated.
4. Both game states cliqueCerto and cliqueErrado present the player with a screen that gives them three choices: go to the next question, restart the game or quit. (If the current question was the last of the 80 available, the option to go to the next question isn’t present.)
5a. If the player chooses to go to the next question, the game state changes to jogar and a new question is presented.
5b. If the player chooses either restart or quit. The game state changes to placar (scoreboard) which displays his score. There are two buttons on this screen, one to restart and one to quit.
6. Clicking the restart button changes the game state to reset and shows a screen saying that the game is restarting and then the game is restarted. Clicking the quit button changes the game state to quit and shows a screen saying that the game is stopping and then the game closes.

My problem is that sometimes when going from step 4 to step 5b, it skips 5b and goes directly to step 6. That is, sometimes when the player answers a question and then chooses to restart or quit, the program skips the step of showing the score page and goes straight to the restarting or quitting procedure.

If I don’t hard restart the game (i.e, I close the game instead of using the games restart button.) in subsequent games, going from step 4 to step 5b seems to ALWAYS skip 5b and goes straight to 6.

The last time I had a problem I couldn’t figure out, someone pointed out that in one of my loops I didn’t have a necessary RETURN statement. I don’t know if that’s causing this problem too. I’m at a loss as to how to fix this.

Any help or suggestions will be appreciated.
Attachments
be-simple_present_07.love
(4 MiB) Downloaded 44 times
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: bug - program SOMETIMES skips score display screen

Post by grump »

Remove all code that has nothing to do with the problem, until you have a minimal program left that shows the error. If you still can't find the cause of the error, post the minimal program.
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Re: bug - program SOMETIMES skips score display screen

Post by randy0428 »

I don’t know how I would go about doing this. Getting to the point in the game where you would choose to restart or quit would require the game to be played, so I don’t see how it would be possible to remove any of the “game playing” code. The rest of the code is necessary to do the procedure that contains the “bug”. I don’t know what I could remove.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: bug - program SOMETIMES skips score display screen

Post by erasio »

He's asking you to do the first bugfixing step.

It may be that in the end it's just something you don't understand, undocumented or poorly documented behavior.

But more likely it's a mistake you made somewhere.

You have dropped 1686 lines of code onto us. In non English code. With no documentation and comments in non English.

Understanding all of that and finding your problem takes a lot of time. If you have a code snippet that causes issues. We'll gladly help. But spending hours orientating in your code and finding the bug. That's too much to ask.

So. The request to you is to find out where the bug is. Usually this is done by replacing snippets of code with default values / behaviors. That you know to be correct and as expected. By doing this, you can start to tell which parts of the code aren't responsible for the bug.

And by the process of elimination eventually end up at the code snippet that is responsible.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: bug - program SOMETIMES skips score display screen

Post by grump »

Yeah, but that is basically how finding bugs works: reducing the program to the relevant parts and check them for correctness. You built the program, you know best about its logic and structure. It's much, much harder for other people to understand your code and identify the relevant parts. If you can't do it with your own program, I doubt that anyone else is willing to do it for you.

You don't need to play the game to get to the point where the bug occurs, just set your state variables to what they should be at that point and jump right to step 6. You don't need to actually click on anything, you can just directly call the functions a click would trigger. You don't need animation and other visual stuff, etc...
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

Re: bug - program SOMETIMES skips score display screen

Post by randy0428 »

Thanks to all who have commented. I'm new to this, especially the debugging.

I appreciate the comments and will take them to heart in learning how to debug.

When I submitted this I didn't really expect anyone to read all of the code, especially since much of it is in Portuguese. I think I was really more hoping for someone to say something like, "This kind of error is GENERALLY a result of x, y or z." and then I could look for places where I could have made that kind of mistake.

You suggestions have given me some ideas to try.

Again, thanks for your input and I'll check this post and post updates here as I progress, so please don't hesitate to add other ideas.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: bug - program SOMETIMES skips score display screen

Post by Sir_Silver »

If I understood your problem correctly, in your placar.lua file, in the restartJogo function, just add this "estadoPlacar.restart = false"

Code: Select all

restartJogo = function(dt)
    if estadoPlacar.restart == true then
      resetOuQuit.resetOuQuit = "reset"
      estadoPlacar.restart = false
      resetOuQuit.resetJogo(dt)
    end
  end,
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: bug - program SOMETIMES skips score display screen

Post by grump »

Silver Dude rocking the house. Excellent.
randy0428
Citizen
Posts: 51
Joined: Sun Jul 31, 2016 10:19 am

RESOLVED: Re: bug - program SOMETIMES skips score display screen

Post by randy0428 »

Thanks for your input Sir_Silver.
After many hours, I found where the problem was. It was in the placar file, like Sir_Silver identified, but I had a different solution.

In the mousereleased part of this file I changed it to:

Code: Select all

mousereleased = function(x, y, button)
   --CLIQUES DO MOUSE
    
    if emPlacarRestart( x, y ) then
      resetOuQuit.resetOuQuit = "reset"
      estadoJogo = "resetOuQuit"
      return
    end
    
    if emPlacarQuit( x, y ) then
      resetOuQuit.resetOuQuit = "quit"
      estadoJogo = "resetOuQuit"
      return
    end
  end
This change moved the restart and quit operations to the resetOuQuit game state (estadoJogo) and I eliminated the restartJogo and quitJogo from this file. I had to make some changes to the reset_ou_quit.lua file.

When I made those changes I also discovered some variable problems in that file. In the print statments I had 2 variables, text and corDaCaixa. These variables were defined inside a function, so they were nil in the print statements because these statements were outside the function. So I had to rework those two variables.

If anyone wants to see the final result or just the two files I changed to get this to work, I'll be happy to post them, but I don't want to take up love2d's server space if no one is interested.

And thanks again to all who commented.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 41 guests