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

Help! unknown error happened

Started by maydaylinus, 09 October 2012 - 10:31 AM
maydaylinus #1
Posted 09 October 2012 - 12:31 PM
I wrote a basic program and all of a sudden they say there is a error!
My code

term.clear()
local tArgs = {...}
local dx, dy, dz
local dx = tonumber(tArgs[1])
local dy = tonumber(tArgs[2])
local dz = tonumber(tArgs[3])
local x, y, z, dif
local gdcx, gdcy, gdcz
local mm = 1
local curdirec
local xtm, ytm, ztm
local dxn, dyn, dzn
local xn, yn, zn
local zcount = tonumber(0)
local zdestroy = tonumber(0)
local xcount = tonumber(0)
local xdestroy = tonumber(0)
local ytogo = tonumber(0)
local ycount = tonumber(0)
local ydestroy = tonumber(0)

print("Target corrdinents: "..dx)
rednet.open("right")
x, y, z = gps.locate(5)
print("X is equal to "..x)
print("Y is equal to "..y)
print("Z is equal to "..z)

--movement Script
if turtle.forward() then
	 gdcx, gdcy, gdcz = gps.locate(5)
	  print("gdcx equal to "..gdcx)
	 print("gdcy equal to "..gdcy)
	 print("gdcz equal to "..gdcz)
	 turtle.back()
else
	 turtle.dig()
	 turtle.forward()
	 gdcx, gdcy, gdcz = gps.locate(5)
	 print("gdcx equal to "..gdcx)
	 print("gdcy equal to "..gdcy)
	 print("gdcz equal to "..gdcz)
	 turtle.back()
   
  end
--checking Script
if gdcx > x then
	 curdirec = "4"
	 print("Current direction: West")
shell.run("left")
print("1")
elseif gdcx < x then
	 curdirec = "2"
	 print("Current direction: East")
    shell.run("right")
   print("1")  
elseif gdcz < z then
	 curdirec = "1"
	 print("current direction: North")
elseif gdcz > z then
	 curdirec = "3"
	 print("Current direction: South")
  shell.run("left")
  shell.run("left")
   
else
	 print("error detected, repeat setup")
end


if dx < 0 then
dxn = 0-dx
--print("debug1:true "..dxn)
else
dxn = dx
--print("debug1.false: "..dxn)
end
if dz < 0 then
dzn = 0-dz
--print("debug2.true: "..dzn)
else
dzn = dz
--print("debug2.false: "..dzn)
end
if x < 0 then
xn = 0-x
--print("debug3.true: "..xn)
else
xn = x
--print("debug3.false : "..xn)
end
if z < 0 then
zn = 0-z
--print("debug4.true: "..zn)
else
zn = z
--print("debug4.false: "..zn)
end
if y < dy then
  ytravi = dy - y
  ytravdir = 1
elseif y > dy then
  ytrav = y - dy
  ytravdir = 2
elseif y == dy then
  ytrav = 0
  ytravdir = 0
else
   print("An unknown Error detected! T.T")
end

--move z
if zn < dzn then
  ztrav = dzn - zn
  ztravdir = 1  -- going to south.
  --print("factor1, true "..ztrav)
  --rint("factor2, true "..ztravdir)
  elseif zn > dzn then
  ztrav = zn- dzn
  ztravdir = 2 --going to north.
  --print("factor1, false "..ztrav)
  --print("factor2, true "..ztravdir)
elseif zn == dzn then
  ztrav = 0 --going nowhere
  ztravdir = 0
else
   print("Unknown error!") 
  end
  if ztravdir == 1 then
    shell.run("left")
shell.run("left")
for a=1, ztrav do
    if turtle.forward() then
	  zcount = zcount + 1
    elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   zcount = zcount + 0
   ytrav = ytrav + 1
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   zdestroy = zdestroy + 1
end
end
shell.run("left")
shell.run("left")
end
if ztravdir == 2 then
 
for b=1, ztrav do
    if turtle.forward() then
	  zcount = zcount + 1
    elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   zcount = zcount + 0
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   zdestroy = zdestroy + 1
end
end

end
 
if ztraveldir == 0 then
   print("I will stay right Here.!")
end
--move x

if xn < dxn then
  xtrav = dxn - xn
  xtravdir = 1 --going west
elseif x > dxn then
  xtrav = xn - dxn
  xtravdir = 2 -- going east
elseif xn == dxn then
  xtrav = 0
  xtravdir = 0
end
print("test "..xtrav)

if xtravdir == 1 then
   shell.run("left")
   print("1")
   for c=1, xtrav do
	 if turtle.forward() then
	  xcount = xcount + 1
   print("2")
    elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   xcount = xcount + 0
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   xdestroy = xdestroy + 1
end
   end
shell.run("right")
   end

if xtravdir == 2 then
    shell.run("right")
print("1")
for d=1, xtrav do
if turtle.forward() then
	  xcount = xcount + 1
   print("2")
    elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   xcount = xcount + 0
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   xdestroy = xdestroy + 1
end
end
shell.run("left")
end
The error says can't find the string xtrav …. It used to work fine, so please help!

The error part
if xn < dxn then
  xtrav = dxn - xn
  xtravdir = 1 --going west
elseif x > dxn then
  xtrav = xn - dxn
  xtravdir = 2 -- going east
elseif xn == dxn then
  xtrav = 0
  xtravdir = 0
end
print("test "..xtrav)
TangentDelta #2
Posted 09 October 2012 - 12:48 PM
It appears as if you don't have xtrav define previously. Stick "xtrav=0" near the top where the other variables are defined.
ChiknNuggets #3
Posted 09 October 2012 - 12:59 PM
can you take a picture of the error?, it really can help
maydaylinus #4
Posted 09 October 2012 - 01:34 PM
I can't seens to use the picture function…
but here is the error code
call:203: attempt to concatenate string and nil.

I will put the url here : https://lh4.googleusercontent.com/XuRdB8_WNfT1OfoUC6JTUomR8VpFEQjv3N2MNtBM_B7fAdN9Aa1I9fmT_6B5ycHtj5PV8SMrBx8
sjele #5
Posted 09 October 2012 - 01:41 PM
Non of the bigger and lessthen here, ever gets called, so xtrav will be nil

if xn < dxn then
  xtrav = dxn - xn
  xtravdir = 1 --going west
elseif x > dxn then
  xtrav = xn - dxn
  xtravdir = 2 -- going east
elseif xn == dxn then
  xtrav = 0
  xtravdir = 0
end
print("test "..xtrav)

I will try to find out why in a sec.
and then you are trying to connect to strings, witch one is xtrav is and thats nil
maydaylinus #6
Posted 09 October 2012 - 02:04 PM
I thought I defined it above, so when I put it into a math equation it becomes a number not a String?
maydaylinus #7
Posted 09 October 2012 - 02:07 PM
I changed the code abit a there is no more error but there is a big problem,
This part is readed:
local dx, dy, dz
local dx = tonumber(tArgs[1])
local dy = tonumber(tArgs[2])
local dz = tonumber(tArgs[3])
local x, y, z, dif
local gdcx, gdcy, gdcz
local mm = 1
local curdirec
local xtm, ytm, ztm
local dxn, dyn, dzn
local xn, yn, zn
local zcount = tonumber(0)
local zdestroy = tonumber(0)
local xcount = tonumber(0)
local xdestroy = tonumber(0)
local ytogo = tonumber(0)
local ycount = tonumber(0)
local ydestroy = tonumber(0)
local xtrav, xtravdir
local ztrav, ztravdir

print("Target corrdinents: "..dx)
rednet.open("right")
x, y, z = gps.locate(5)
print("X is equal to "..x)
print("Y is equal to "..y)
print("Z is equal to "..z)
--movement Script
if turtle.forward() then
	 gdcx, gdcy, gdcz = gps.locate(5)
	  print("gdcx equal to "..gdcx)
	 print("gdcy equal to "..gdcy)
	 print("gdcz equal to "..gdcz)
	 turtle.back()
else
	 turtle.dig()
	 turtle.forward()
	 gdcx, gdcy, gdcz = gps.locate(5)
	 print("gdcx equal to "..gdcx)
	 print("gdcy equal to "..gdcy)
	 print("gdcz equal to "..gdcz)
	 turtle.back()
  
  end
--checking Script
if gdcx > x then
	 curdirec = "4"
	 print("Current direction: West")
shell.run("left")
print("1")
elseif gdcx < x then
	 curdirec = "2"
	 print("Current direction: East")
	shell.run("right")
   print("1")  
elseif gdcz < z then
	 curdirec = "1"
	 print("current direction: North")
elseif gdcz > z then
	 curdirec = "3"
	 print("Current direction: South")
  shell.run("left")
  shell.run("left")
  
else
	 print("error detected, repeat setup")
end

if dx < 0 then
dxn = 0-dx
--print("debug1:true "..dxn)
else
dxn = dx
--print("debug1.false: "..dxn)
end
if dz < 0 then
dzn = 0-dz
--print("debug2.true: "..dzn)
else
dzn = dz
--print("debug2.false: "..dzn)
end
if x < 0 then
xn = 0-x
--print("debug3.true: "..xn)
else
xn = x
--print("debug3.false : "..xn)
end
if z < 0 then
zn = 0-z
--print("debug4.true: "..zn)
else
zn = z
--print("debug4.false: "..zn)
end
if y < dy then
  ytravi = dy - y
  ytravdir = 1
elseif y > dy then
  ytrav = y - dy
  ytravdir = 2
elseif y == dy then
  ytrav = 0
  ytravdir = 0
else
   print("An unknown Error detected! T.T")
end
--move z
if zn < dzn then
  ztrav = dzn - zn
  ztravdir = 1  -- going to south.
  --print("factor1, true "..ztrav)
  --rint("factor2, true "..ztravdir)
  elseif zn > dzn then
  ztrav = zn- dzn
  ztravdir = 2 --going to north.
  --print("factor1, false "..ztrav)
  --print("factor2, true "..ztravdir)
elseif zn == dzn then
  ztrav = 0 --going nowhere
  ztravdir = 0
else
   print("Unknown error!")
  end
  if ztravdir == 1 then
	shell.run("left")
shell.run("left")
for a=1, ztrav do
	if turtle.forward() then
	  zcount = zcount + 1
	elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   zcount = zcount + 0
   ytrav = ytrav + 1
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   zdestroy = zdestroy + 1
end
end
shell.run("left")
shell.run("left")
end
if ztravdir == 2 then

for b=1, ztrav do
	if turtle.forward() then
	  zcount = zcount + 1
	elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   zcount = zcount + 0
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   zdestroy = zdestroy + 1
end
end

end

if ztraveldir == 0 then
   print("I will stay right Here.!")
end
if xn < dxn then
  xtrav = dxn - xn
  xtravdir = 1 --going west
  print("1")
elseif x > dxn then
  xtrav = xn - dxn
  xtravdir = 2 -- going east
  print("2")
elseif xn == dxn then
  xtrav = 0
  xtravdir = 0
end
print("Loaded")
But things after is not…
if xtravdir == 1 then
   shell.run("left")
   print("1")
   for c=1, xtrav do
	 if turtle.forward() then
	  xcount = xcount + 1
   print("2")
	elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   xcount = xcount + 0
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   xdestroy = xdestroy + 1
end
   end
shell.run("right")
   end

if xtravdir == 2 then
	shell.run("right")
print("1")
for d=1, xtrav do
if turtle.forward() then
	  xcount = xcount + 1
   print("2")
	elseif turtle.up()then
	  turtle.forward()
   print("I moved Up")
   xcount = xcount + 0
   else
	  turtle.digUp()
   print("sorry, I Have to dig you..")
   xdestroy = xdestroy + 1
end
end
shell.run("left")
end
sjele #8
Posted 09 October 2012 - 02:09 PM

   end
shell.run("right")
   end
? why 2 ends there?
If you are getting <eof> then thats your problem
maydaylinus #9
Posted 09 October 2012 - 02:11 PM
And yeah, the shell.run commands are just basic codes that make turtle turns..

no <eof> though

There is no error actually, just the program ignored what I coded..
maydaylinus #10
Posted 09 October 2012 - 02:17 PM
now it just loads to the
print("loaded")
and stop, a snap shot:https://lh4.googleusercontent.com/B9j4dB4-nZxwYkI5NGgWfQF1eJ9l18dMNFg2i5Oam0E4It9rzNi5TDo8Lwhpl90SyQz_dogabmw
maydaylinus #11
Posted 09 October 2012 - 04:16 PM
Everything fixed And I have my first programs that lead turtle to a XYZ location! thanks for the help!
code:
term.clear()
local tArgs = {...}
local dx, dy, dz
local dx = tonumber(tArgs[1])
local dy = tonumber(tArgs[2])
local dz = tonumber(tArgs[3])
local x, y, z, dif
local gdcx, gdcy, gdcz
local mm = 1
local curdirec
local xtm, ytm, ztm
local xn = tonumber(0)
local zn = tonumber(0)
local dxn = tonumber(0)
local dzn = tonumber(0)
local zcount = tonumber(0)
local zdestroy = tonumber(0)
local xcount = tonumber(0)
local xdestroy = tonumber(0)
local ytogo = tonumber(0)
local ycount = tonumber(0)
local ydestroy = tonumber(0)
local xtrav = tonumber(0)
local xtravdir = tonumber(0)
local ztrav = tonumber(0)
local ztravdir = tonumber(0)
local ycurrent = tonumber(0)
local ytrav = tonumber(0)
local ytravdir = tonumber(0)
--print("Target corrdinents: "..dx)
rednet.open("right")
x, y, z = gps.locate(5)
print("X is equal to "..x)
print("Y is equal to "..y)
print("Z is equal to "..z)

--movement Script
if turtle.forward() then
	 gdcx, gdcy, gdcz = gps.locate(5)
	  --print("gdcx equal to "..gdcx)
	 --print("gdcy equal to "..gdcy)
	 --print("gdcz equal to "..gdcz)
	 turtle.back()
else
	 turtle.dig()
	 turtle.forward()
	 gdcx, gdcy, gdcz = gps.locate(5)
	 --print("gdcx equal to "..gdcx)
	 --print("gdcy equal to "..gdcy)
	 --print("gdcz equal to "..gdcz)
	 turtle.back()
   
  end
--checking Script
if gdcx > x then
	 curdirec = "4"
	 print("Current direction: West")
shell.run("left")
print("1")
elseif gdcx < x then
	 curdirec = "2"
	 print("Current direction: East")
    shell.run("right")
   print("1")  
elseif gdcz < z then
	 curdirec = "1"
	 print("current direction: North")
elseif gdcz > z then
	 curdirec = "3"
	 print("Current direction: South")
  shell.run("left")
  shell.run("left")
   
else
	 print("error detected, repeat setup")
end


if dx < 0 then
dxn = 0-dx
--print("debug1:true "..dxn)
else
dxn = dx
--print("debug1.false: "..dxn)
end
if dz < 0 then
dzn = 0-dz
--print("debug2.true: "..dzn)
else
dzn = dz
--print("debug2.false: "..dzn)
end
if x < 0 then
xn = 0-x
--print("debug3.true: "..xn)
else
xn = x
--print("debug3.false : "..xn)
end
if z < 0 then
zn = 0-z
--print("debug4.true: "..zn)
else
zn = z
--print("debug4.false: "..zn)
end
if dy < 0 then
print("error setup, turtle is not strong enough to go through bedrock!")
else
--print("y is correct!")
ycurrent = y
--print(ycurrent)
end
if xn < dxn then
  xtrav = dxn - xn
  xtravdir = 1  -- going to south.
  --print("factor1, true "..ztrav)
  --rint("factor2, true "..ztravdir)
  elseif xn > dxn then
  xtrav = xn- dxn
  xtravdir = 2 --going to north.
  --print("factor1, false "..ztrav)
  --print("factor2, true "..ztravdir)
elseif xn == dxn then
  xtrav = 0 --going nowhere
  xtravdir = 0
else
   print("Unknown error!") 
  end
  if xtravdir == 1 then
   
shell.run("left")
for c=1, xtrav do
    if turtle.forward() then
	  xcount = xcount + 1
    elseif turtle.up()then
	  turtle.forward()
   --print("I moved Up")
   ycurrent = ycurrent + 1
   xcount = xcount + 0
   else
	  turtle.digUp()
   --print("sorry, I Have to dig you..")
   xdestroy = xdestroy + 1
end
end
shell.run("right")
end
if xtravdir == 2 then
  shell.run("right")
for d=1, xtrav do
    if turtle.forward() then
	  xcount = xcount + 1
    elseif turtle.up()then
	  turtle.forward()
   --print("I moved Up")
   ycurrent = ycurrent +1
   xcount = xcount + 0
   else
	  turtle.digUp()
   --print("sorry, I Have to dig you..")
   xdestroy = xdestroy + 1
end
end
shell.run("left")
end
 
if xtraveldir == 0 then
   print("I will stay right Here.!")
end

--move z
if zn < dzn then
  ztrav = dzn - zn
  ztravdir = 1  -- going to south.
  --print("factor1, true "..ztrav)
  --rint("factor2, true "..ztravdir)
  elseif zn > dzn then
  ztrav = zn- dzn
  ztravdir = 2 --going to north.
  --print("factor1, false "..ztrav)
  --print("factor2, true "..ztravdir)
elseif zn == dzn then
  ztrav = 0 --going nowhere
  ztravdir = 0
else
   print("Unknown error!") 
  end
  if ztravdir == 1 then
    shell.run("left")
shell.run("left")
for a=1, ztrav do
    if turtle.forward() then
	  zcount = zcount + 1
    elseif turtle.up()then
	  turtle.forward()
   --print("I moved Up")
   ycurrent = ycurrent +1
   zcount = zcount + 0
	 else
	  turtle.digUp()
   --print("sorry, I Have to dig you..")
   zdestroy = zdestroy + 1
end
end
shell.run("left")
shell.run("left")
end
if ztravdir == 2 then
 
for b=1, ztrav do
    if turtle.forward() then
	  zcount = zcount + 1
    elseif turtle.up()then
	  turtle.forward()
   --print("I moved Up")
   zcount = zcount + 0
   ycurrent = ycurrent +1
   else
	  turtle.digUp()
   --print("sorry, I Have to dig you..")
   zdestroy = zdestroy + 1
end
end

end
 
if ztraveldir == 0 then
   --print("I will stay right Here.!")
end
--move y
if ycurrent < dy then
  ytrav = dy - ycurrent
    ytravdir = 2
elseif ycurrent > dy then
  ytrav = ycurrent - dy
  ytravdir = 1
elseif ycurrent == dy then
  ytrav = 0
  ytravdir = 0
  --print(":P/>/>")
end 
  --print(ytrav)
  --print(ytravdir)
 
if ytravdir == 1 then
    for e=1, ytrav do
    if turtle.down() then
    --print("Down, sir!")
    else
    turtle.digDown()
    turtle.down()
    --print("It may hurt bro.")
    end
  end
  print("mission doned!")
end
if ytravdir == 2 then
	 for f=1, ytrav do
	    if turtle.up() then
	    --print("up, sir!")
    else
	 turtle.digUp()
    print("Here I come!") 
end
end
print("mission doned!")
end

if ytravdir == 0 then
   print("mission doned!")
  end