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

[LUA] [ERROR] attempt to call string

Started by sirdabalot, 25 March 2012 - 04:54 PM
sirdabalot #1
Posted 25 March 2012 - 06:54 PM
I'm making my own api and am trying to create a function that displays all the stuff in a turtles inventory in a gui fashion:


function invPrint()
slot1 = tostring(turtle.getItemCount(1))
slot2 = tostring(turtle.getItemCount(2))
slot3 = tostring(turtle.getItemCount(3))
slot4 = tostring(turtle.getItemCount(4))
slot5 = tostring(turtle.getItemCount(5))
slot6 = tostring(turtle.getItemCount(6))
slot7 = tostring(turtle.getItemCount(7))
slot8 = tostring(turtle.getItemCount(8))
slot9 = tostring(turtle.getItemCount(9))
print("=============")
print("|   |   |   |")
print("| " .. slot1 .. " | " .. slot2 .. " | " .. slot3 " |")	 //error
print("| " .. slot4 .. " | " .. slot5 .. " | " .. slot6 " |")
print("| " .. slot7 .. " | " .. slot8 .. " | " .. slot9 " |")
print("|   |   |   |")
print("=============")
end

When I ask it to start printing the actual numbers [print("| " .. slot1 .. " | " .. slot2 .. " | " .. slot3 " |")] the code returns an attempt to call string error, I am not sure why this is happening as the print function works with strings, does it not? Any help on this matter will be much appreciated.
Advert #2
Posted 25 March 2012 - 07:27 PM
My guess would be that you've overwritten one of the functions with a string.

What line number are you erroring in?
sirdabalot #3
Posted 25 March 2012 - 07:40 PM
My guess would be that you've overwritten one of the functions with a string.

What line number are you erroring in?
you mean in the whole api or on that one section of code?
Advert #4
Posted 25 March 2012 - 07:43 PM
The line # for the whole API wouldn't help me much, as I still wouldn't know which line was causing the error.
sirdabalot #5
Posted 25 March 2012 - 07:46 PM
The line # for the whole API wouldn't help me much, as I still wouldn't know which line was causing the error.
He he, sorry, good point. It is line 13.
zedalius #6
Posted 25 March 2012 - 08:06 PM
im not sure, but don't
you need to put it like this

" ..slot3.. "
instead of

" .. slot3 "

Please note, that i "suck" at Lua :b
Advert #7
Posted 25 March 2012 - 08:07 PM
I see the error now; you forgot the concatenation operator:


print("| " .. slot1 .. " | " .. slot2 .. " | " .. slot3 " |") -- Missing last .., same with lines below  
print("| " .. slot4 .. " | " .. slot5 .. " | " .. slot6 " |")
print("| " .. slot7 .. " | " .. slot8 .. " | " .. slot9 " |")

Should be:


print("| " .. slot1 .. " | " .. slot2 .. " | " .. slot3 .. " |")
print("| " .. slot4 .. " | " .. slot5 .. " | " .. slot6 .. " |")
print("| " .. slot7 .. " | " .. slot8 .. " | " .. slot9 .. " |")

Also, note that comments start with a – in lua, not // like some other languages.
sirdabalot #8
Posted 25 March 2012 - 08:11 PM
my bad, and ahhhhhhhhh, tut stupid minor mistakes, thank you :(/>/>