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

How to print a table?

Started by Carrots084, 21 July 2014 - 10:32 PM
Carrots084 #1
Posted 22 July 2014 - 12:32 AM
Okay, I know there are a lot of these posts already out there. None of them have worked for me. I tried textutils.serialize(suggestions) and then printing it but it didn't print.
Spoiler

--os.pullEvent = os.pullEventRaw

--Ask for name, set as variable: pName
print("What is your in-game name?")
local pName = read()
print("How many suggestions do you have?")
local sugNum = read()
sugNum = tonumber(sugNum)
suggestions = { }
for i = 1, sugNum do
x = 1
print("What is your suggestion?")
local suggestion = read()
table.insert(suggestions, x, suggestion)
x = x + 1
end
print(suggestions)
PixelToast #2
Posted 22 July 2014 - 12:42 AM

print(texutils.serialize(suggestions))
not

texutils.serialize(suggestions)
print(suggestions)
you can also do what alissa did

for i=1, #suggestions do --"#" is length of table/string.
  print(i .. ": " .. suggestions[i]) --Prints, in example, 1: Hello
end
Edited on 21 July 2014 - 10:49 PM
Cranium #3
Posted 22 July 2014 - 12:43 AM
Using textutils should work properly.

print(textutils.serialize(suggestions))
Carrots084 #4
Posted 22 July 2014 - 05:49 PM
Thank you so much!