Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: monkey0506 on Fri 30/09/2005 13:35:21

Title: Line breaks in error messages (SUGGESTION? BUG? HELP?)
Post by: monkey0506 on Fri 30/09/2005 13:35:21
I'm not sure exactly how line breaks work with labels, but I'm trying to display one in an error message, and my code is taking a beating because of it.  I have a line like:

AbortGame("Invalid parameter 'topic' to function 'ScrollingDialog::GetText'.\
Range: 0 to %d\
Value: %d", eScrollingDialog_MaxTopics, topic);


So this one line of code spans three lines in the editor so that I can put a line break in.  This is causing the editor some difficulties, because I noticed yesterday that I tried to compile some code and got an error saying "Error (line 214): undefined symbol 'topic'" or something to that effect.  However, line 214 (or whichever line it was), contained '}', and that was it.

I scrolled down about 20 - 30 lines and found the culprit of the error, but it was too far down in the actual script.  So, the question was is there a better way to do this?

Or do I need to suggest a better way, or perhaps a bug fix so that the lines will be the same in the error message and the actual script in this case?
Title: Re: Line breaks in error messages (SUGGESTION? BUG? HELP?)
Post by: strazer on Fri 30/09/2005 17:17:43
Line breaks in strings are done with the [ character.
I take it the problem is doing a line break in the editor? I don't know if that's possible.
You can of course just break up the string like this:


string message;
StrCopy(message, "Invalid parameter 'topic' to function 'ScrollingDialog::GetText'.");
AbortGame("%s[Range: 0 to %d[Value: %d", message, eScrollingDialog_MaxTopics, topic);
Title: Re: Line breaks in error messages (SUGGESTION? BUG? HELP?)
Post by: Pumaman on Fri 30/09/2005 19:11:10
However, [ does not work with AbortGame messages since they are passed straight to the Windows MessageBox. Since doing '\n' is not supported in the script, I don't actually think this is possible at the moment.
Title: Re: Line breaks in error messages (SUGGESTION? BUG? HELP?)
Post by: Kweepa on Fri 30/09/2005 20:17:53
Could you force a \n into the string at every linebreak, like this?


string message;
StrFormat(message, "Invalid parameter 'topic' to function 'ScrollingDialog::GetText'.[Range: 0 to %d[Value: %d", eScrollingDialog_MaxTopics, topic);
int i = 0; while (i < StrLength(message)) { if (message[i] == '[') message[i] = 13; i++; }
AbortGame(message);
Title: Re: Line breaks in error messages (SUGGESTION? BUG? HELP?)
Post by: Scorpiorus on Fri 30/09/2005 23:22:28
I too noticed that AbortGame error messages are usually rather long because of the message length itself plus additional debug parameters.

Would it be a possibility to have multi-line string constants support in the editor for a future version?

Ex:

String errMessage = "Struct::Function: the parameter"
Ã,  Ã,  Ã,  Ã,  Ã, Ã,  Ã,  Ã,  Ã,  Ã, Ã, Ã,  Ã,  Ã,  Ã,  Ã, Ã,  Ã,  Ã, "%d is out of range (%d..%d)";

Also, then long text speech strings could be arranged nicely.



[EDIT]:

I just tried...

String errMessage = "Struct::Function: the parameter
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, %d is out of range (%d..%d)";

...which seems compiled fine but I'm not sure how official it is and thus whether it would always work properly or some problems may occur, as monkey_05_06 says.
Title: Re: Line breaks in error messages (SUGGESTION? BUG? HELP?)
Post by: Pumaman on Sat 01/10/2005 11:26:15
One rather hacky way of doing it would be this:

String message = String.Format("Invalid parameter 'topic' to function 'ScrollingDialog::GetText'.%cRange: 0 to %d%cValue: %d", 13, eScrollingDialog_MaxTopics, 13, topic);

that way, you actually insert a carriage return character (13) directly into the message -- try it and see if it works.
Title: Re: Line breaks in error messages (SUGGESTION? BUG? HELP?)
Post by: monkey0506 on Sun 02/10/2005 03:47:40
I'll look into that, perhaps Monday.  But I still don't like the fact that it screws up the line numbering (i.e., the editor interprets the string as one line, even though it's spread over several...).