Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Comma separator in the print command appends varying spaces to separated output.

Why does the "," separator in the print command vary the number of spaces between these two lines in the output console?

x = {"one", "two", "three", label = "console"}

y = {"fee", "fi", "foo", "fum"}

x.y = y -- i.e. x["y"] = y -- the table y

print('x.y[2] =', x.y[2]) -- fi (a couple of spaces) ???
print('x["y"][2] =', x["y"][2]) -- fi (no spaces) ???

Tagged:

Comments

  • Posts: 2,020

    You can use append .. instead if you want to precisely control output formatting

  • dave1707dave1707 Mod
    Posts: 9,730

    @chrisgeeting The print statement prints values separated by a comma on tab boundaries. The tab boundaries are position 1, 5, 9, 13, 17, 21, 25, 29, etc.

  • Alright Dave, got it....tab boundary. Thanks!
    And yes, I noticed the concatenation operator gave me more control. Thanks Jimbo!

  • Posts: 688

    However be aware if the item your concatenating is not a number or a string (ie, is a boolean, a table or nil) then Lua will throw an error but using a , is always safe

  • Posts: 1,976

    @TechDojo You can always call toString(x) on it to make sure you don't get an error.

Sign In or Register to comment.