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

Need a real pro - Tables Error

Started by LuaEclipser, 20 February 2013 - 02:48 PM
LuaEclipser #1
Posted 20 February 2013 - 03:48 PM
Well I Had This Code and when i try to print the Merchant it gives me Table:RANDOM #s


npc = {
" -------- ",
"|		   |",
"|		   |",
" --------",
"Merchant"
}
function printM()
	 print(npc)
end
printM()

i no this is nooby but i need help! (you will be in credits of my game :)/>
LuaEclipser #2
Posted 20 February 2013 - 03:57 PM

Thanks All1!
BigSHinyToys #3
Posted 20 February 2013 - 04:02 PM

npc = {
" -------- ",
"|				 |",
"|				 |",
" --------",
"Merchant"
}
function printM()
for i,v in pairs(npc) do
		 print(v)
end
end
printM()
untested but it should work
Lyqyd #4
Posted 20 February 2013 - 04:03 PM
for i=1, #npc do
print(npc)
end

You have to print the string at each index of the table.
LuaEclipser #5
Posted 20 February 2013 - 04:08 PM
Thank You Guys! Creds to both you

one more question


what if i want to print the guy in certain places on the map (or even randomly move!)

sorry if i am wasting your time
tesla1889 #6
Posted 20 February 2013 - 04:12 PM
that gets a little complicated

basically you have two options:
  • add spaces to the beginning of each line to get the horizontal position and print nothing to get the vertical position
  • or you could set the position of the cursor for each line to where the next line should be
LuaEclipser #7
Posted 20 February 2013 - 04:14 PM
or could write it all to a function ,"
LuaEclipser #8
Posted 20 February 2013 - 04:18 PM
any ideas how to make them all move around and print maps?
BigSHinyToys #9
Posted 20 February 2013 - 04:26 PM
This program does what you want.
http://pastebin.com/ggTZXsyh
LuaEclipser #10
Posted 20 February 2013 - 04:44 PM
Thank You ^^
R167 #11
Posted 20 February 2013 - 08:18 PM
for i=1, #npc do
print(npc)
end

You have to print the string at each index of the table.
This is my personal favorite way to do stuff. Always works for this purpose. :)/>
LuaEclipser #12
Posted 26 February 2013 - 03:14 PM
This program does what you want.
http://pastebin.com/ggTZXsyh

umm ya i got this error message while running this

i copyed it PERFECTYLE —-
( expected to close )
LuaEclipser #13
Posted 26 February 2013 - 03:15 PM
This program does what you want.
http://pastebin.com/ggTZXsyh

umm ya i got this error message while running this

i copyed it PERFECTYLE —-
( at line 31 expected t oclose ) at line 30

my code —-

http://pastebin.com/ggTeYTAx
BigSHinyToys #14
Posted 26 February 2013 - 08:22 PM
http://pastebin.com/H0bSVFZA
Found a few problems with your code fixed.
LuaEclipser #15
Posted 01 March 2013 - 12:43 PM
thank you alot! you have helped me soooo much