BUG: GetTextWidth for multiple"%" symbols

Started by GarageGothic, Wed 02/08/2006 00:03:58

Previous topic - Next topic

GarageGothic

I'm aware that the symbol "%" is used to mask itself for use in Strings, so that "%%" displays as "%". However, when using GetTextWidth on a string containing "%%" the function calculates the width of both symbols even though only one is displayed. This is rather inconvenient when parsing user-input and having to limit to a certain (displayed) length.

monkey0506

Really...this is quite interesting. I think I may have encountered this before...without...realizing what was happening. Glad to hear the bug got reported though.

SSH

But how is gettextwidth to know whether you will print the string one way or another?

Code: ags

String x="abc%%d";
Display("%s", x); // One way: prints two %
Display(x); // Another, prints one %

12

Alynn

Would / (or is it \ my brain is foggy) % do what you want? I know it works for quotation marks

SSH

I presume you're displaying this with a GUI label, but do GUI labels need the %% anyway? Don't they just display the text verbatim?
12

GarageGothic

I print it using RawDraw. To be honest, I don't really give a shit about it myself - I just deactivated the functionality for Shift+5 so the player can't enter it. But I figured it was an error in the way GetTextWidth worked. I wasn't aware about the Display("%s", x)/Display(x) difference, so possibly this is "as designed".

Pumaman

It's a difficult one. I guess really, GetTextWidth should correspond to the width that you'll get with RawPrint/DisplaySpeech/Display, all of which do the %% thing .. so you're probably right, it's a bug.

strazer

Also, the GetTextWidth function doesn't recognize the [ line break character, so
12345
and
12345[123
don't return the same width.

SMF spam blocked by CleanTalk