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

Error: attempt to compare number with string expected, got number

Started by CH4K1B, 29 December 2012 - 03:19 AM
CH4K1B #1
Posted 29 December 2012 - 04:19 AM
Hi!
I'm French and I use a program to recover wood with turtles
and I get this error "attempt to compare number with string expected got number"


function detecteMarqueSol()
marque = -1
for i = 9, 12 do
turtle.select(i)

if(turtle.compareDown()) then
marque = i
end
end

return marque
end


-- Démarrage...
i = 1
turtle.select(16)
while i <= 4 do
if turtle.compare() then
turtle.turnLeft()
i = 5
else
turtle.turnRight()
i = i + 1
end
end

while true do

marque = detecteMarqueSol()

if(marque > 0) then
if marque == 12 then
if turtle.detect() then
turtle.turnRight()
end
elseif marque == 11 then
turtle.turnLeft()
if not turtle.detect() then
turtle.select(1)
turtle.place()
end
turtle.turnRight()
elseif marque == 10 then
if turtle.getFuelLevel() < 96 then
turtle.turnLeft()
turtle.select(5)
turtle.suck()
if turtle.getItemCount(5) > 2 then
turtle.drop(turtle.getItemCount(5) - 2)
end
turtle.refuel(1)
turtle.turnRight()
end
elseif marque == 9 then
turtle.select(1)
if turtle.getItemCount(1) < 13 then
turtle.turnLeft()
turtle.suck()

if turtle.getItemCount(1) > 13 then
turtle.drop(turtle.getItemCount(1) - 13)
end

turtle.turnRight()
end
end
end

turtle.forward()

end



it is not me who made ​​this program.
Here is the original link: http://pastebin.com/K3GnDV3w

Thank you in advance for your help.
remiX #2
Posted 29 December 2012 - 04:44 AM
Give us the number that is included within the error, please.
And use [code]your code here[/code] tags.
CH4K1B #3
Posted 29 December 2012 - 05:14 AM
the number that is included in the error is 45
Viproz #4
Posted 29 December 2012 - 05:45 AM
L'erreur en soi est très simple, à un endroit tu essai de comparer un string avec un int, il faut utiliser tonumber() pour transformer un string en int

Dans ton erreur tu devrais avoir nomDuProgramme:nombre là j'ai compté jusqu'à la ligne 45 mais j'ai du me tromper vu que ça ne correspond à rien !

Sorry for english i'm too tired to translate
CH4K1B #5
Posted 29 December 2012 - 05:53 AM
L'erreur en soi est très simple, à un endroit tu essai de comparer un string avec un int, il faut utiliser tonumber() pour transformer un string en int

Dans ton erreur tu devrais avoir nomDuProgramme:nombre là j'ai compté jusqu'à la ligne 45 mais j'ai du me tromper vu que ça ne correspond à rien !

Sorry for english i'm too tired to translate
thank you for your response if line 45 is
turtle.getFuelLevel () <96 then
Viproz #6
Posted 29 December 2012 - 06:02 AM
So i realy don't understand, mabe try tonumber(turtle.getFuelLevel()) < 96
CH4K1B #7
Posted 29 December 2012 - 06:18 AM
its not working it writes "bios:338: [string "p1"]:45: unexpected symbol"
Viproz #8
Posted 29 December 2012 - 07:02 AM
Returns the current fuel level of the turtle, this is the number of blocks the turtle can move. If turtleNeedFuel = 0 then it yields "unlimited".

I think we have our solution ! (wiki)
CH4K1B #9
Posted 29 December 2012 - 07:11 AM
Sorry I do not really understand what should I do? :s
Viproz #10
Posted 29 December 2012 - 07:28 AM

if turtle.getFuelLevel() ~= "unlimted" then
  if turtle.getFuelLevel() < 96 then
    -- your thinks
  end
end

you can compare a string and an int only with == or ~= so this code would work
CH4K1B #11
Posted 29 December 2012 - 07:39 AM
Ho thank you very much it works!