Why are the enemies not appearing on the screen?

What do I need to change to trigger the highscore entry screen?

Ok now I have access to the highscore entry screen, I did by not setting stage.score to 0 every time a new life was started. I will report back later.

Ok I have it running now …

Are you compiling with -fpermissive? That is generally not a good idea because it allows a lot of incorrect code to compile.

Compilation errors and warnings are your friend. Don’t ignore them. If you use GCC I think you should at least use the -Wall flag. -Wextra also enables many useful warnings. Fixing your code so that you get none of these warnings will prevent a lot of problems.

… but I cant seem to trigger the highscore entry screen

Does the function doNameInput even get called? Why not? Is it because newHighscore is still null? Why does addHighscore leave newHighscore null? Is it because the score that gets passed to addHighscore is zero? Why is it zero? Do you do anything before calling this function that would reset it to zero?

I’m being overly verbose here just to show the kind of questions that you should be asking yourself while debugging.

Right now addHighscore (and initHighScores) is being called every time you die. Is this what you want or should it only get called once when you run out of lives?


I also noticed that the game seems to continue to run in the background after you run out of lives because the lives continue to drop below zero if you wait at the highscore screen.

ok will fix that soon. In the meantime can you show me why the highscore entry program keeps repeating the text when its entered? Thanks.

It’s probably because you never reset dot.inputText so doNameInput keeps adding the same text over and over.

Another problem is that if you receive two SDL_TEXTINPUT events in quick succession then doNameInput might only see the last one. To avoid this you probably want to concatenate the text input to dot.inputText rather than replacing it.

Please can I ask where I should reset dot.inputText?

Thank you

Also what line of code do I need to reset it?

Thanks

Do it after you’re finished using it.

Alternatively, you could call doNameInput directly from the event loop when receiving the SDL_TEXTINPUT event. Then you could get rid of dot.inputText and pass e.text.text as an argument to the function instead. EDIT: In that case you might want to split up the function and handle the backspace and return keys in separate functions (e.g. that gets called in response to a SDL_KEYDOWN event).

1 Like

I got it running and now I am trying to put theenterhighscore screen in a separate game state but its not responding to text input. Why is that? What am I missing?

As far as I can tell I’m running doNameInput and drawNameInput when newHighscore != NULL

Ok that’s fixed. It was a typo in the logic. Now I’m getting a crash when switching my game state to HIGHSCORESCREEN when return is pressed. Can anyone tell me how to fix it.

Thank you kindly.

Ok got that fixed, it was something to do with newHighScore being set to NULL so I changed the logic and it works.