Line breaks in error messages (SUGGESTION? BUG? HELP?)

Started by monkey0506, Fri 30/09/2005 13:35:21

Previous topic - Next topic

monkey0506

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:

Code: ags
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?

strazer

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:

Code: ags

string message;
StrCopy(message, "Invalid parameter 'topic' to function 'ScrollingDialog::GetText'.");
AbortGame("%s[Range: 0 to %d[Value: %d", message, eScrollingDialog_MaxTopics, topic);

Pumaman

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.

Kweepa

Could you force a \n into the string at every linebreak, like this?

Code: ags

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);
Still waiting for Purity of the Surf II

Scorpiorus

#4
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.

Pumaman

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.

monkey0506

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...).

SMF spam blocked by CleanTalk