Hi!
I'm attempting to format a string using the text [[ ]] thing. I have come across unexpected behavior that I don't know how to solve.
local a = [[Potatos = %s Carrots = %s ]] -- This is a multi-line text. string.format(a, "YES", "NO") -- Format the a string with string. print(a) -- Result: -- Potatos = %s --Carrots = %s --Expected result: -- Potatos = YES -- Carrots = NO
How would I get this to print like this? I've looked at so many wiki articles and nothing seems to be working.
Thanks, Nathan.
Your problem is that you aren't updating the 'a' variable. String functions will not update the environment for you, you have to redefine it yourself.
local a = [[Potatos = %s Carrots = %s ]] a = string.format(a,"YES","NO") print(a)
This can be shortened as well.
print(tostring([[Potatoes = %s Carrots = %s]]):format("YES","NO"))