This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LuaEclipser's profile picture

Why my tables printing weird?

Started by LuaEclipser, 03 April 2013 - 12:47 PM
LuaEclipser #1
Posted 03 April 2013 - 02:47 PM
this is my code - http://pastebin.com/sFrM5je4

it is printing all weird

|
how? this V
Spoiler

can someone tell me WHY this is happening and how to fix it? (maybe a fixed code?) thanks!!




-LuaEclipser
PixelToast #2
Posted 03 April 2013 - 04:26 PM
because the string contains backslashes (the escape operator), replace all instances of "\" with "\\" in the strings
LuaEclipser #3
Posted 03 April 2013 - 04:33 PM
because the string contains backslashes (the escape operator), replace all instances of "\" with "\\" in the strings
D: that ruins the ASCII art D: any other way?
Lyqyd #4
Posted 03 April 2013 - 07:40 PM
No, the point is that it un-ruins the ASCII art. It looks funny in the code, but prints correctly. You could also put each line in block quotes instead.
theoriginalbit #5
Posted 03 April 2013 - 07:51 PM
and by block quotes he means


local someVar = [[multi-line
string where
you can use \ freely]]

a example (all of the below will print a diamond to the screen)
Spoilersingle line, requires \\ to be used to display a \

asciiArt = "  /\\\n /  \\\n|	|\n \\  /\n  \\/"
print(asciiArt)

in a table, still requires \\

asciiArt = {
  "  /\\",
  " /  \\",
  "|	|",
  " \\  /",
  "  \\/"
}

for _,v in ipairs(asciiArt) do
  print(v)
end

using block quotes [[ ]] no \\ is needed to print \

asciiArt = [[  /\
/  \
|	|
\  /
  \/]]

print(asciiArt)

table using block quotes, no need to use \\ for \

asciiArt = {
  [[  /\]],
  [[ /  \]],
  [[|	|]],
  [[ \  /]],
  [[  \/]]
}

for _,v in ipairs(asciiArt) do
  print(v)
end
Edited on 03 April 2013 - 05:52 PM