Using [ in strings

Started by AdamM, Fri 20/02/2009 23:13:57

Previous topic - Next topic

AdamM

As we all know the character [ formats a new line in strings. In one instance I want to use the character itself rather than a new line. I understand the usual way to do this is to 'escape' it by inserting a backslash (as in \[) but this doesn't seem to be working. Does it have something to do with the string I'm using being a GUI label? Can someone verify that escaping [ works or not with GUI label text?

Trent R

I just tried out both Display("text\[text"); and Label.Text="text\[text"; and they both worked....  Can we see the code? (not that it should matter)


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

AdamM

No, it doesn't seem to matter now that I've discovered it is happening in all my labels in all my GUIs. In a Display function, "text\[text" appears normally as "text[text", but in any GUI label it appears as

text\
text

And this is even before I've compiled - I can see it happen in the editor when I change the label's Text in the property grid. What on earth could be causing this?

Trent R

I did it using a script function, are you trying to do it straight from the Properties pane? Try using a Label.Text=string call in your game_start.

If you don't want to bother trying to fix it, another way to do it would be to use another character like @, and switch it in your font.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

AdamM

#4
Whether script or property grid, it has the same effect. And yes I do want to bother fixing it.

EDIT: Look! I started a new game, and it's still doing it! It must be something in the editor! Look!


Pumaman

This does appear to be a bug, GUI Labels don't support the \[ combination. I'll look into a fix.

AdamM

Thanks CJ!

Two bug reports in one lifetime? When you're hot, you're hot!

Trent R

#7
Huh, I thought it worked for me before...

Well if it is a bug, you can use the workaround I described. Replace \[ with @ or some other character that you won't use. Then in your font (if your using ttf, google for free editors) change the @ to look like [

[Edit]: After looking at some of your previous posts, it seems you already know about the work around. Sorry I wasn't a help at all.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

AdamM

Aw, don't say that. I always appreciate help.  :)

I doubt my game will be finished any time soon, so I'll just wait for the fix.

monkey0506

#9
IIRC GetTextWidth and GetTextHeight don't properly register the '\[' escaped char either. I believe it either reads both of them or it just ignores it being escaped...I forgot. It actually lead to me writing a function to completely remove all of the '[' characters from a String, get the width of the rest of the text, get the width of a single '[' char and adjust appropriately. It's a very bothersome workaround.

Nevermind. I forgot. Because I was displaying them at the same time as they were being added to the String I didn't want them being escaped while they were being added, so what I ended up actually doing was writing a function to escape the '['s dynamically so I can get the appropriate width/height as needed. It's still bothersome having to do that, but it works as intended.

Pumaman

This is now resolved in SP1: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=36781.0
Please make sure that the problem is fixed for you.

AdamM

Everything is dandy! Many thanks!

Monsieur OUXX

This thread is older than 120 days but I dug it up for archiving and research's sake:

Most of the questions raised in this discussion have been synthesised in this wiki page.
 

SMF spam blocked by CleanTalk