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

How to print a table?

Started by axel.codeFail(), 07 March 2014 - 02:31 AM
axel.codeFail() #1
Posted 07 March 2014 - 03:31 AM
I'm trying to make it so that if you enter a letter, then it'll print out some words, but I can't figure out how to print out a whole table, and I can't find any other topics that seem to help.

This is what I have so far:

term.clear()
local mytable = {"Oak Logs","Iron Ore","Snow Blocks"}
while true do
  rank = read()
  term.setCursorPos(1,1)
  term.setBackgroundColor(colors.black)
  if rank==a then
    term.clear()
    term.setTextColor(colors.red)
    print("Rank A Mine")
    term.setTextColor(colors.green)
    print(mytable[1])
    print(mytable[2])
    print(mytable[3])
    sleep(5)
  end
end

As of right now, when I enter a, it just sets the CursorPos to 1,1 and does nothing else. It doesn't even clear the a that I entered.

Any help would be greatly appreciated. :)/>
theoriginalbit #2
Posted 07 March 2014 - 03:38 AM
your problem is because read returns a string and you're comparing it against a variable that doesn't exist (nil)

so instead of this

if rank == a then
it should be

if rank == "a" then
axel.codeFail() #3
Posted 07 March 2014 - 03:58 AM
It worked! :)/>
-.- Now I feel lame, but thanks for the help.
Edited on 07 March 2014 - 02:59 AM