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

item:13: attempt to compare number with string expected, got number

Started by Inumel, 09 May 2013 - 05:12 PM
Inumel #1
Posted 09 May 2013 - 07:12 PM
Okay so this is my code




print("Select which slot you wish to use 1,16")
ic = read()
b = tonumber(ic)
x = turtle.getItemCount(B)/>
print("How many items do you want to use? 0,64")
z = read()
if x == z then
  rs.setOutput("left", true)
  sleep(5)
  rs.setOutput("left", false)
else
  if x > z then
  print("Too many items in slot 5")
  end
  if x < z then
  print("Not enough items in slot 5")
end
end

Running this, it works fine up until x > z(and i assume x< z), It gives me the error that is the title of this post.. Problem is, I am new, so I don't know how to work around this(Or fix it!)

So i come to you pros, and help is appreciated :)/>
H4X0RZ #2
Posted 09 May 2013 - 07:42 PM
You have
getItemCount(B)/>/>/>/>
unstead
getItemCount(B)/>/>/>/>
:)/>/>/>/>

I've cleaned it up:

 print("Select which slot you wish to use 1,16") 
ic = tonumber(read() )
x = turtle.getItemCount(B)/>/>/>/>/> 
print("How many items do you want to use? 0,64") 
z = tonumber(read()) 
if x == z then 
rs.setOutput("left", true) 
sleep(5) 
rs.setOutput("left", false) 
elseif x > z then 
print("Too many items in slot 5") --why slot 5?
elseif x < z then print("Not enough items in slot 5") 
end

EDIT:
Damn emoticon detection -.-
the b in the second snippet has to be lowercase.
Inumel #3
Posted 09 May 2013 - 07:50 PM
You have
getItemCount(B)/>/>/>
unstead
getItemCount(B)/>/>/>
:)/>/>

I've cleaned it up:

print("Select which slot you wish to use 1,16")
ic = tonumber(read() )
x = turtle.getItemCount(B)/>/>/>/>
print("How many items do you want to use? 0,64")
z = tonumber(read()) if x == z then
rs.setOutput("left", true)
sleep(5)
rs.setOutput("left", false)
elseif x > z then
print("Too many items in slot 5") --why slot 5?
end
if x < z then print("Not enough items in slot 5") end
end

EDIT:
Damn emoticon detection -.-
the b in the second snippet has to be lowercase.

Thanks for the help! :)/> it was slot 5 because that's what I had it set to, before I added the user input! I forgot to change, thanks!