MaddDogg Posted May 11, 2010 Share Posted May 11, 2010 Hi! I just ran into a problem, I didn't notice ever before. I have a script, which is at one point supposed to send the player a message. The text for this message is first read from an xml file, then put into a string.format function and finally used in guiCreateLabel. It looks like this: xml file: <text catg="CHARACTER" identifier="LEVEL_UP_TEXT" text="You just leveled up!\nNew level: %d" /> Lua script: GUI_LevelUp["text"] = guiCreateLabel(1606,480,148,32,string.format(getLanguageText("CHARACTER", "LEVEL_UP_TEXT"), getElementData(getLocalPlayer(), "level")),false) My problem now is that the new line character ('\n') is output not as a new line but rather as the characters '\n' itself. This is caused by string.format for some reason. Now I don't really know, how to get the new line into the final string. Can someone please help me with this issue? And no, I can't just leave the xml stuff out of it and put the string directly into string.format Thanks in advance, Madd Link to comment
dzek (varez) Posted May 11, 2010 Share Posted May 11, 2010 try doing something like: GUI_LevelUp["text"] = guiCreateLabel(1606,480,148,32,string.gsub(string.format(getLanguageText("CHARACTER", "LEVEL_UP_TEXT"), getElementData(getLocalPlayer(), "level")), "\\n", "\n"),false) i didnt test it, but maybe it will work i had same problem when i was scripting in another programming lang few days ago Link to comment
MaddDogg Posted May 11, 2010 Author Share Posted May 11, 2010 Thanks! It worked! But why is string.format escaping the new line character? I mean, in the original string there is this character. But as soon as string.format processes it, it does that. And it only happens, when I pass the string through a variable to it instead of directly writing it into the function. Link to comment
dzek (varez) Posted May 11, 2010 Share Posted May 11, 2010 dont ask me maybe somebody knows the reason Link to comment
PacMan Posted May 12, 2010 Share Posted May 12, 2010 The reason is simple, when extracting data from XML file, all backslash (\) are duplicated. Link to comment
MaddDogg Posted May 12, 2010 Author Share Posted May 12, 2010 Ohh okay, thank you. Now I understand why. Thanks for the help. Link to comment
dzek (varez) Posted May 12, 2010 Share Posted May 12, 2010 so this is not a string format but xml.. interesting ^^ Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now