Jump to content

Error Messages Print Twice


reepblue
 Share

Go to solution Solved by Josh,

Recommended Posts

]This old code demonstrates it well. 

#include "UltraEngine.h"

using namespace UltraEngine;

bool PrintColorHook(const Event& e, shared_ptr<Object> extra)
{
    //https://learn.microsoft.com/en-us/windows/console/getstdhandle#handle-disposal
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    if (e.text.Left(8) == "Warning:")
    {
        SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    }
    else if (e.text.Left(6) == "Error:")
    {
        SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
    }
    else
    {
        SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    }
    return true;
}

int main(int argc, const char* argv[])
{
    ListenEvent(EVENT_PRINT, NULL, PrintColorHook);

    Print("Here is a normal text message.");
    Print("Warning: Here is a warning.");
    Print("Here is a normal text message.");
    Print("Error: Here is an error.");
    Print("Here is a normal text message.");

    return 0;
}

 

Output:

Here is a normal text message.
Warning: Here is a warning.
Here is a normal text message.
Error: Here is an error.
Error: Here is an error.
Here is a normal text message.

E:\Repos\UltraEngine\Game\Game_d.exe (process 13544) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...