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

[Error] For Input String: "1Sw" Really Don't Know What It Is

Started by blipman17, 23 August 2013 - 06:14 AM
blipman17 #1
Posted 23 August 2013 - 08:14 AM
i am making a turtle navigation code, and with the function goto() i get an error with every good parameter. does anyone know what this error means? for input string: "1sw". if you want to do goto() you should first do setplace(), just so the turtle knows its starting point.

--[[
... api for turtles
]]--
fuellevel = 10
function setMinFuel(level)
fuellevel=level
end
function fuel()
if turtle.getFuelLevel()<fuellevel then
print("insert fuel in bottom right slot")
while turtle.getItemCount(16)<1 do
sleep(1)
end
turtle.select(16)
if turtle.refuel()==false then
print("inserted invalid fuel source")
while turtle.refuel()==false do
sleep(1)
end
end
end
end
currentplace={}
--[[
currentplace
   [1] = relative position on x axis
   [2] = relative position on y axis
   [3] = relative position on z axis
   [4] = relative facing (north, east, south, west)
   [5] = absolute position on x axis
   [6] = absolute position on y axis
   [7] = absolute position on z axis
   [8] = absolute facing (north, east, south, west)
can be called without any arguments
]]--
function setplace(a, b, c, d)
if a ==nil then a=0 end
if b ==nil then b=0 end
if c==nil then c=0 end
if d==nil then d="north" end
currentplace[1]=a
currentplace[2]=b
currentplace[3]=c
currentplace[4]=d
if gps.locate()~=nil then
print("got gps signal")
currentplace[5], currentplace[6], currentplace[7] = gps.locate()
-- gps facing code
location={}
if turtle.detect()==false then
print("can go forward")
fuel()
turtle.forward()
location[1], location[2], location[3]=gps.locate()
if location[3]-currentplace[7]==-1 then
currentplace[8]="north"
turtle.back()
return true
elseif location[3]-currentplace[7]==1 then
currentplace[8]="south"
turtle.back()
return true
elseif location[1]-currentplace[5]==-1 then
currentplace[8]="west"
turtle.back()
return true
else
currentplace[8]="east"
turtle.back()
return true
end
else
right()
if turtle.detect()==false then
fuel()
turtle.forward()
location[1], location[2], location[3]=gps.locate()
if location[3]-currentplace[7]==-1 then
currentplace[8]="north"
fuel()
turtle.back()
left()
return true
elseif location[3]-currentplace[7]==1 then
currentplace[8]="south"
fuel()
turtle.back()
left()
return true
elseif location[1]-currentplace[5]==-1 then
currentplace[8]="west"
fuel()
turtle.back()
left()
return true
else
currentplace[8]="east"
fuel()
turtle.back()
left()
return true
end
else
right()
if turtle.detect()==false then
fuel()
turtle.forward()
location[1], location[2], location[3]=gps.locate()
if location[3]-currentplace[7]==-1 then
currentplace[8]="north"
fuel()
turtle.back()
right()
right()
return true
elseif location[3]-currentplace[7]==1 then
currentplace[8]="south"
fuel()
turtle.back()
right()
right()
return true
elseif location[1]-currentplace[5]==-1 then
currentplace[8]="west"
fuel()
turtle.back()
right()
right()
return true
else
currentplace[8]="east"
fuel()
turtle.back()
right()
right()
return true
end
else
right()
if turtle.detect()==false then
fuel()
turtle.forward()
location[1], location[2], location[3]=gps.locate()
if location[3]-currentplace[7]==-1 then
currentplace[8]="north"
fuel()
turtle.back()
right()
return true
elseif location[3]-currentplace[7]==1 then
currentplace[8]="south"
fuel()
turtle.back()
right()
return true
elseif location[1]-currentplace[5]==-1 then
currentplace[8]="west"
fuel()
turtle.back()
right()
return true
else
currentplace[8]="east"
fuel()
turtle.back()
right()
return true
end
else
right()
return false
end
end
end
end
-- end of gps facing code
end
end --of function
function up()
if turtle.detectUp()==false then
fuel()
turtle.up()
currentplace[2]=currentplace[2]+1
if currentplace[6]~=nil then
currentplace[6]=currentplace[6]+1
end
end
end
function down()
if turtle.detectDown()==false then
fuel()
turtle.down()
currentplace[2]=currentplace[2]-1
if currentplace[6]~=nil then
currentplace[6]=currentplace[6]-1
end
end
end
function left()
turtle.turnLeft()
if currentplace[4]== "north" then
currentplace[4]="west"
elseif currentplace[4]== "west" then
currentplace[4]= "south"
elseif currentplace[4]=="south" then
currentplace[4]="east"
elseif currentplace[4]=="east" then
currentplace[4]="north"
end
if currentplace[8]== "north" then
currentplace[8]="west"
elseif currentplace[8]== "west" then
currentplace[8]= "south"
elseif currentplace[8]=="south" then
currentplace[8]="east"
elseif currentplace[8]=="east" then
currentplace[8]="north"
end
end
function right()
turtle.turnRight()
if currentplace[4]== "north" then
currentplace[4]="east"
elseif currentplace[4]== "west" then
currentplace[4]= "north"
elseif currentplace[4]=="south" then
currentplace[4]="west"
elseif currentplace[4]=="east" then
currentplace[4]="south"
end
if currentplace[8]== "north" then
currentplace[8]="east"
elseif currentplace[8]== "west" then
currentplace[8]= "north"
elseif currentplace[8]=="south" then
currentplace[8]="west"
elseif currentplace[8]=="east" then
currentplace[8]="south"
end
end

--[[ north is z negatief
west is x negatief]]--

--type 1 as a parameter to break down obstacles
function forward(m)
if turtle.detect()==false then
fuel()
turtle.forward()
if currentplace[4]=="north" then
currentplace[3]=currentplace[3]-1
elseif currentplace[4]=="west" then
currentplace[1]=currentplace[1]-1
elseif currentplace[4]=="south" then
currentplace[3] = currentplace[3]+1
elseif currentplace[4]=="east" then
currentplace[1]=currentplace[1]+1
end
if currentplace[8]=="north" then
currentplace[7]=currentplace[7]-1
elseif currentplace[8]=="west" then
currentplace[5]=currentplace[5]-1
elseif currentplace[8]=="south" then
currentplace[7] = currentplace[7]+1
elseif currentplace[8]=="east" then
currentplace[5]=currentplace[5]+1
end
elseif m==1 then
turtle.dig()
fuel()
turtle.forward()
if currentplace[4]=="north" then
currentplace[3]=currentplace[3]-1
elseif currentplace[4]=="west" then
currentplace[1]=currentplace[1]-1
elseif currentplace[4]=="south" then
currentplace[3] = currentplace[3]+1
elseif currentplace[4]=="east" then
currentplace[1]=currentplace[1]+1
end
if currentplace[8]=="north" then
currentplace[7]=currentplace[7]-1
elseif currentplace[8]=="west" then
currentplace[5]=currentplace[5]-1
elseif currentplace[8]=="south" then
currentplace[7] = currentplace[7]+1
elseif currentplace[8]=="east" then
currentplace[5]=currentplace[5]+1
end
end
end
function getplace()
return currentplace
end
--moce, gps/relative
function orient(mode, facing)
if mode=="gps" then --gps mode
if facing == currentplace[8] then
--nothing
elseif currentplace[8]=="north" and facing=="west" then
left()
elseif currentplace[8]=="west" and facing=="south" then
left()
elseif currentplace[8]=="south" and facing=="east" then
left()
elseif currentplace[8]=="east" and facing=="north" then
left()
else
repeat
right()
until currentplace[8]==facing
end
else --normal mode
if facing == currentplace[4] then
--nothing
elseif currentplace[4]=="north" and facing=="west" then
left()
elseif currentplace[4]=="west" and facing=="south" then
left()
elseif currentplace[4]=="south" and facing=="east" then
left()
elseif currentplace[4]=="east" and facing=="north" then
left()
else
repeat
right()
until facing==currentplace[4]
end
-- end of mode selection
end
-- end of function
end
--mode, gps/relative
function goto(mode, xAxis, yAxis, zAxis)
if mode=="gps" then
--gpsmode
if xAxis-currentplace[7]>0 then
orient("gps", "east")
elseif xAxis-currentplace[7]<0 then
orient("gps", "west")
end
while xAxis~=currentplace[7] do
forward()
end
if zAxis-currentplace[5]>0 then
orient("gps", "south")
elseif zAxis-currentplace[5]<0 then
orient("gps", "north")
end
while zAxis~=currentplace[5] do
forward()
end
if yAxis-currentplace[6]<0 then
while yAxis~=currentplace[6] do
down()
end
elseif yAxis-duccentplace[6]>0 then
while yAxis~=currentplace[6] do
up()
end
end
elseif mode=="relative" then
--relative positioning mode
if xAxis-currentplace[3]>0 then
orient("gps", "east")
elseif xAxis-currenplace[3]<0 then
orient("gps", "west")
end
while xAxis~=currentplace[3] do
forward()
end
if zAxis-currentplace[1]>0 then
orient("gps", "south")
elseif zAxis-currentplace[1]<0 then
orient("gps", "north")
end
while zAxis~=currentplace[1sw] do
forward()
end
if yAxis-currentplace[2]<0 then
while yAxis~=currentplace[2] do
down()
end
elseif yAxis-duccentplace[2]>0 then
while yAxis~=currentplace[2] do
up()
end
end
else
print("invalid mode defined")
end
end
setplace()
goto("gps", 546, 65, 533)
Zudo #2
Posted 23 August 2013 - 08:21 AM
Change the name of the variable 1sw to something else.
blipman17 #3
Posted 23 August 2013 - 08:37 AM
Change the name of the variable 1sw to something else.
oh, derp. i feel like sutch an idiot. thanx.
Zudo #4
Posted 23 August 2013 - 08:53 AM
Change the name of the variable 1sw to something else.
oh, derp. i feel like sutch an idiot. thanx.
It's a really weird error, so don't feel like an idiot :)/>
theoriginalbit #5
Posted 23 August 2013 - 09:01 AM
Yeh I have to agree, don't feel too bad, too all of us a while to figure it out the first time we ever encountered it, because, well it's not the most useful and helpful error message.