Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua Exporter: The backslash (\) gets doubled each time used in a string #933

Closed
MadByteDE opened this issue May 5, 2015 · 3 comments
Closed

Comments

@MadByteDE
Copy link

Lua escape sequences get malformed when added into a string in tiled. for example this line:

"Hello \n World"

In the tmx file the string is saved as expected. However in the lua export it magically got two backslashs what causes that my text won't get printed properly.

properties = {
            ["text"] = "Hello \\n World"
          }
@bjorn
Copy link
Member

bjorn commented May 5, 2015

Well, if you want your text to be "Hello \n World", then it is necessary to escape the \ in the output otherwise Lua would interpret your \n as a newline character. By escaping strings properly, Tiled makes sure that the string appears exactly as written in Tiled on the Lua side.

Unfortunately, it is at the moment impossible to put a newline in a property in Tiled. The only way to achieve this is to edit the TMX file in a text editor. In this case, Tiled will export it to Lua as \n.

Eventually I want to add a text area for editing multiline properties to the properties editor. This is covered by issue #205.

Until then, you could of course implement your own search-and-replace to turn "\n" into an actual newline character.

@bjorn bjorn closed this as completed May 5, 2015
@MadByteDE
Copy link
Author

otherwise Lua would interpret your \n as a newline character

Thats exactly what I want it to do.

Tiled makes sure that the string appears exactly as written in Tiled on the Lua side.

This isn't true.When typing "Hello \n World" in tiled I get "Hello \n World" as output at the lua side.
This looks clearly like a bug to me.

I don't need multiline support in Tiled. I just want to have the exact same line I typed exported to the lua file.

Maybe I just don't get what you wrote there. Sorry then.
So you saying it is impossible to export the exact same line I type in tiled to lua ?

@bjorn
Copy link
Member

bjorn commented May 5, 2015

This isn't true.When typing "Hello \n World" in tiled I get "Hello \n World" as output at the lua side. This looks clearly like a bug to me.

That's because you're reading the Lua code. When you would print the string from Lua to the console, it would output exactly like you wrote it in Tiled.

I don't need multiline support in Tiled. I just want to have the exact same line I typed exported to the lua file.

That would easily lead to invalid Lua code if you're not careful with what you type. Most notably, users would be struggling to insert any special character like \ or " into their values and would suddenly have to remember to escape these for the sake of the Lua export.

Really, if you want a newline character in the string, you probably need multiline support in Tiled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants