- Posts: 6
- Joined: Sat May 28, 2022 3:54 pm
- Real Name: Thomas Mueller
Thomas Mueller wrote:
- Code: Select all
comp.Text3D1.StyledText:SetExpression("Text([[€]]..string.format("%.4f",3.1415926))")
The problem is the quotation marks. If you have quote marks inside quote marks, you need a way to distinguish between marks that are inside and outside the string. It looks like you already addressed that issue once, with the string literal surrounding your €. You just needed to do it again with the "%.4f" string.
There are two ways of doing it: Either you use different types of string enclosures, or you escape the marks you want to treat differently.
Here's an example of the former:
- Code: Select all
comp.Text3D1.StyledText:SetExpression("Text([[€]]..string.format('%.4f',3.1415926))")
Using single quotes for the interior string prevents it from prematurely ending the exterior string.
Or, as I alluded above, you could use the same string literal notation:
- Code: Select all
comp.Text3D1.StyledText:SetExpression("Text([[€]]..string.format([[%.4f]],3.1415926))")
I usually use the literal on the outside with normal quote marks in the interior, but either way works.
The other method is to use the escape character \ to instruct the script interpreter to ignore the quotation marks:
- Code: Select all
comp.Text3D1.StyledText:SetExpression("Text([[€]]..string.format(\"%.4f\",3.1415926))")
When the interpreter encounters the \", it replaces it with ", but otherwise ignores it for the purpose of parsing the code.
See the Strings chapter of Programming in Lua for more information:
https://www.lua.org/pil/2.4.html