Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to display error messages to user?  (Read 3720 times)

0 Members and 2 Guests are viewing this topic.

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
How to display error messages to user?
« on: September 16, 2012, 12:33:04 am »
In my release version of my craps game, there won't be a console screen.  I've always disliked software that doesn't give the user good error messages and leaves them wondering what happened.  So what's a reliable and easy way to display error messages to the user in the release version of my craps game when using SFML?

For example, suppose a needed background image file is missing or corrupt using this code:

if (!Image.loadFromFile("Images/primarymenu.png"))
{
    // Show the user an error message that the primarymenu image was not found
    //    and show the complete path where the file should be.
    // Wait until user presses ESCAPE or RETURN.

    return QUIT;  //Exits the craps game program.
}

Thanks,
Raptor
« Last Edit: September 16, 2012, 12:36:03 am by Raptor88 »

Atani

  • Newbie
  • *
  • Posts: 30
    • MSN Messenger - atanisoft@hotmail.com
    • AOL Instant Messenger - AtaniSYSOP
    • Yahoo Instant Messenger - atanisoft
    • View Profile
    • Email
Re: How to display error messages to user?
« Reply #1 on: September 16, 2012, 12:45:09 am »
If you are on windows, why not use a modal message box? For other uses perhaps using one of the gui libraries and do something similar?

Mike

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: How to display error messages to user?
« Reply #2 on: September 16, 2012, 01:04:27 am »
Shouldn't be a problem assuming you have a state machine.
In EE (assuming I handled loading errors like that) I'd do:
EE::Sys().AddScreen(new EECrashScreen("Error loading texture smt smt ect.");
EE::Sys() is acess to game core functions and classes and EECrashScreen would be a state that quits the game on any input and only displays the sf::Text with the std string passed to it.
For simplicity I'd also create inline functions like that:
inline void EECriticalTextureLoad(sf::Texture& gtex,const std::string& gstring)
{
if(!gtex.loadFromFile(gstring))
EE::Sys().AddScreen(new EECrashScreen("Error loading texture "+gstring);
}
 
But I (still) don't know how your state engine is laid out so I don't know how much use it is to you.
You could also generate file called CRAPSGAME_ERROR.txt(so the big letters catch attention) near the .exe and dump your crash report there.
Back to C++ gamedev with SFML in May 2023

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: How to display error messages to user?
« Reply #3 on: September 16, 2012, 09:44:42 am »
If you are on windows, why not use a modal message box? For other uses perhaps using one of the gui libraries and do something similar?

Hi Mike,

That's just what I was looking for.  Never heard of a modal message box before so it took a couple of hours of Googling to finally figure out how to use it.

QUESTION:
I had to include <windows.h> to get it to work.  I assume that this means only Windows and my craps game release code needs to be present on the host computer for the messagebox function to work.  Like the .net framework does not have to be installed.  Is that correct?

Sorry for the noob question but I just want to be sure since my whole purpose in coding in C++ and SFML is to not require the .net framework or anything else to be installed on the Windows computer for my craps game program to work.

Thanks for your suggestion!
Raptor
« Last Edit: September 16, 2012, 10:01:35 am by Raptor88 »

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: How to display error messages to user?
« Reply #4 on: September 16, 2012, 09:58:27 am »
But I (still) don't know how your state engine is laid out ...snip...

Hi FRex,

I had previously mentioned in the "Getting user input and displaying formatted text" thread that I planned to use the "Manage different screens in a game" engine for my craps game.  So yes, I'm using that engine with what I've coded so far.

I figured out how to use a modal message box to display my error messages per Mike's (Atani) suggestion.  I'll use that to display any errors that might occur, to the users of my craps game.

Thank you very much for your help, as aways,
Raptor

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: How to display error messages to user?
« Reply #5 on: September 16, 2012, 02:44:18 pm »
I had to include <windows.h> to get it to work.  I assume that this means only Windows and my craps game release code needs to be present on the host computer for the messagebox function to work.  Like the .net framework does not have to be installed.  Is that correct?
Yes it will only work in Windows and it won't need the .NET framework. ;)

If you don't want to use a cross platform GUI but 'native OS API', then you might want to take a look for Sys_Dialog in the Quake 3 source code (Windows, Linux, OS X). It doesn't need to be a good solution, but it was one that I just found while googling a bit. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: How to display error messages to user?
« Reply #6 on: September 16, 2012, 10:34:13 pm »
I had to include <windows.h> to get it to work.  I assume that this means only Windows and my craps game release code needs to be present on the host computer for the messagebox function to work.  Like the .net framework does not have to be installed.  Is that correct?
Yes it will only work in Windows and it won't need the .NET framework. ;)

If you don't want to use a cross platform GUI but 'native OS API', then you might want to take a look for Sys_Dialog in the Quake 3 source code (Windows, Linux, OS X). It doesn't need to be a good solution, but it was one that I just found while googling a bit. ;)

Hi eXpl0it3r,

Thanks for the confirmation regarding message box.  I'll check out the Sys_Dialog GUI.

Thanks!
Raptor