Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 927 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Improved error #441303
05/18/14 16:54
05/18/14 16:54
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline OP
Expert
MasterQ32  Offline OP
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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:
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


Visit my site: www.masterq32.de
Re: Improved error [Re: MasterQ32] #441304
05/18/14 18:29
05/18/14 18:29
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Small nitpicking: You can shorten your message generation code by doing this:
Code:
diag(str_printf(NULL, "\nError %d: %s", errorCode, _chr(str)));



Also solves the undefined behaviour that you are generating there laugh


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Improved error [Re: WretchedSid] #441305
05/18/14 19:32
05/18/14 19:32
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline OP
Expert
MasterQ32  Offline OP
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
what undefined behaviour do you mean?


Visit my site: www.masterq32.de

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1