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

error: attempt to compare string with number.

Started by Trust_95a, 16 October 2012 - 09:40 AM
Trust_95a #1
Posted 16 October 2012 - 11:40 AM
term.clear()
term.setCursorPos(1,1)
local tArgs = {...}
local xto = tArgs[1]
local yto = tArgs[2]
local zto = tArgs[3]
local dir = 0

--[getting the direction (look at calibration)]--
if tArgs[4] == nil then
dirto = 1
elseif tArgs[4] > "3" then
dirto = 1
print("direction to = 1")
elseif tArgs[4] < "0" then
dirto = 1
print("direction to = 1")
else
dirto = tArgs[4]
end
--[acceptions in tArgs]--
if xto == nil or yto == nil or zto == nil then
print("usage: goto <x to> <y to> < z to>... and optinal <set direction>")
return
end
if size == tonumber( tArgs[1]) or size == tonumber( tArgs[2]) or size == tonumber( tArgs[3]) then
print("x,y,z ( and dir ) must be a number")
return
end
--[basics movs.]--
local function turnLeft()
turtle.turnLeft()
dir = dir - 1
  if dir < 0 then
   dir = 3
  end
end
local function turnRight()
turtle.turnRight()
dir = dir + 1
if dir > 3 then
  dir = 0
end
end
rednet.open("right")
local function locate()
x,y,z = gps.locate(3)
end
--[calibration]--
local function calibration()
locate()
if turtle.forward() == false then
  print("impossible calibration")
  return false
else
xf,yf,zf = gps.locate(3)
  if xf == x + 1 then
   dir = 3
   turtle.back()
   return true
  elseif xf == x - 1 then
   dir = 1
   turtle.back()
   return true
  elseif xf == x then
   if zf == z + 1 then
    dir = 0
    turtle.back()
    return true
   elseif zf == z - 1 then
    dir = 2
    turtle.back()
    return true
   end
  end
end
end
--[goto movs.]--
local function gotox()
print(xto)
if xto > x then
  print("grande")
elseif xto < x then
  print("pequeño")
end
end
calibration()
print(x.." "..y.." "..z.." "..dir)
gotox()
rednet.close("right")
Can you help me?¿
I'm doing my own goto program, and it says that my argument isn't a number, when I try to compare the position in X to the X destination.



thanks.
remiX #2
Posted 16 October 2012 - 11:52 AM
What is the number that is within the error code?

EDIT: I might not be right but I think it is line 4,5,6


local tArgs = {...}
local xto = tArgs[1]
local yto = tArgs[2]
local zto = tArgs[3]


You might have to convert them to numbers.


local tArgs = {...}
local xto = tonumber(tArgs[1])
local yto = tonumber(tArgs[2])
local zto = tonumber(tArgs[3])

Trust_95a #3
Posted 16 October 2012 - 12:29 PM
thanks a lot !

I convert them to numbers =)
remiX #4
Posted 16 October 2012 - 02:49 PM
Awesome :D/>/> Feel free to ask if you have any more problems. Everyone gets caught out with setting variables to numbers from an input.