Posted By: MasterQ32
Improved error - 05/18/14 16:54
Hey guys,
was just working again with gamestudio and noticed that debugging is just a PITA.
So i wrote myself a little error message that allows me to improve custom error feedback:
This function allows you to show your custom error codes.
The big difference is that cerror allows you to suppress specific error codes by pressing "Retry".
The function will still log into the diag file but will not show any error message ingame.
Also to be mentioned that the function resets the keyboard via key_pressed(-1) to prevent keys to be hold after an error message.
Here's the snippet:
Have fun!
Felix
was just working again with gamestudio and noticed that debugging is just a PITA.
So i wrote myself a little error message that allows me to improve custom error feedback:
Code:
void cerror(int errorCode, STRING *text);
This function allows you to show your custom error codes.
The big difference is that cerror allows you to suppress specific error codes by pressing "Retry".
The function will still log into the diag file but will not show any error message ingame.
Also to be mentioned that the function resets the keyboard via key_pressed(-1) to prevent keys to be hold after an error message.
Here's the snippet:
Code:
void cerror(int errorCode, STRING *text) { static int killed = 0; static int suppressed[1024]; // Throw error if error code is out of bounds... if(errorCode < 0 || errorCode >= 1024) { cerror(0, "errorCode out of bounds!"); return; } // Build error name STRING *str = "#100"; str_cpy(str, "Error "); str_cat(str, str_for_int(NULL, errorCode)); // Log error diag("\n"); diag(str); diag(": "); diag(str); // Don't show message if system is killed or error is suppressed if(killed) return; if(suppressed[errorCode]) return; int result; result = MessageBox(hWnd, _chr(text), _chr(str), 0x06 | 0x10); if(result == 2) // Cancel { // Kill the program killed = true; sys_exit(NULL); } if(result == 10) // Retry { // Suppress the current message suppressed[errorCode] = true; } // Suppress invalid keys key_pressed(-1); }
Have fun!
Felix