Posted 18 January 2013 - 04:00 PM
so i came up with this gps builder as my first lua program… i have't found any bugs so far, so i think its working all right….
feel free to give me tips or point out how could i improve it.
usage:
setup_gps <x> <y> <z> <f>
facing usage:
N if turtle is facing north
S if turtle is facing south
W if turtle is facing west
E if turtle is facing East
items placing:
slot 1: 4x computers
slot2: 4x wirelss modems
slot 3: 1 floppy disk
slot 4: 1 disk drive
you must enter the turtle actual coords, it could be either your own or minecraft coords.
place the turtle in a open space with nothing above it and should work fine…
bugs:
turtle no longer digs air to check if its a mining turtle. now it places the disk drive than dig it back.
feel free to give me tips or point out how could i improve it.
usage:
setup_gps <x> <y> <z> <f>
facing usage:
N if turtle is facing north
S if turtle is facing south
W if turtle is facing west
E if turtle is facing East
items placing:
slot 1: 4x computers
slot2: 4x wirelss modems
slot 3: 1 floppy disk
slot 4: 1 disk drive
you must enter the turtle actual coords, it could be either your own or minecraft coords.
place the turtle in a open space with nothing above it and should work fine…
Spoiler
local tArgs = { ... }
local uY, count, tX, tY, tZ, face = 1, 1, tArgs[1], tArgs[2], tArgs[3], tArgs[4]
function faceSouth()
tZ = tZ + 1
if face == 'N' then
turtle.turnLeft()
turtle.turnLeft()
elseif face == 'W' then
turtle.turnLeft()
elseif face == 'E' then
turtle.turnRight()
else
faceUsage()
return false
end
goToSky()
end
function goToSky()
while turtle.up() do
uY = uY + 1
end
tY = tY + uY
placeComputer()
end
function goToGround()
while turtle.down() do
end
end
function placeComputer()
turtle.select(1)
turtle.place()
turtle.back()
turtle.select(2)
turtle.place()
turtle.down()
turtle.forward()
turtle.select(4)
turtle.place()
turtle.select(3)
turtle.drop()
setComputer()
end
function goToSouthPos()
turtle.turnLeft()
turtle.turnLeft()
for i = 1, 4 do
turtle.forward()
tZ = tZ + 1
end
tZ = tZ + 2 -- + 2 to compensate for turtle pos before turning left and the pos the computer is placed
placeComputer()
end
function goToEastPos()
turtle.down()
turtle.down()
turtle.down()
tY = tY - 3
for i = 1, 4 do
turtle.forward()
end
tZ = tZ - 3
turtle.turnRight()
turtle.forward()
turtle.forward()
tX = tX + 3
placeComputer()
end
function goToWestPos()
turtle.down()
for i = 1, 6 do
turtle.forward()
tX = tX - 1
end
turtle.up()
placeComputer()
end
function setComputer()
turtle.down()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.up()
setUpDisk(tX,tY,tZ)
turtle.up()
peripheral.call("front", "turnOn")
turtle.down()
turtle.suck()
turtle.dig()
turtle.up()
sleep(2)
peripheral.call("front", "reboot")
if count == 1 then
count = count + 1
goToSouthPos()
elseif count == 2 then
count = count + 1
goToEastPos()
elseif count == 3 then
count = count + 1
goToWestPos()
elseif count == 4 then
goToGround()
end
end
function setUpDisk(x,y,z)
print("Computer number "..count)
print("<x>"..x.." <y>"..y.." <z>"..z)
local st = fs.open("disk/startup", "w")
local gps_run = "shell.run('gps','host',"..x..","..y..","..z..")"
st.writeLine("local startup = fs.open('startup', 'w')")
st.writeLine("startup.writeLine(\""..gps_run.."\")")
st.writeLine("startup.close()")
st.close()
end
function usage()
print("usage:")
print("setup_gps <x> <y> <z> <f>")
end
function placingSetUp()
print("---------------------------------------")
print("Please place items in the following order:")
print("Slot 1: 4x computers")
print("Slot 2: 4x wirelesse modems")
print("Slot 3: 1x floopy disk")
print("Slot 4: 1x disk drive")
print("---------------------------------------")
end
function checkItems()
if turtle.getItemCount(1) == 4
and turtle.getItemCount(2) == 4
and turtle.getItemCount(3) == 1
and turtle.getItemCount(4) == 1
then
return true
else
placingSetUp()
return false
end
end
function checkTurtleType()
turtle.select(4)
turtle.place()
if turtle.dig() then
return true
else
print("You must use a mining turtle in order to run this program")
return false
end
end
function faceUsage()
print("-----------------")
print("face parameter:")
print("S if facing south")
print("N if facing north")
print("E if facing east")
print("W if facing west")
print("-----------------")
return false
end
function checkArguments()
if #tArgs ~= 4 then
usage()
return false
elseif type(tonumber(tX)) ~= "number" then
print("<x> has to be a number")
return false
elseif type(tonumber(tY)) ~= "number" then
print("<y> has to be a number")
return false
elseif type(tonumber(tZ)) ~= "number" then
print("<z> has to be a number")
return false
else
return true
end
end
function checkFuel()
if turtle.getFuelLevel() < 1000 then
print("Not enough fuel")
print("Fuel level has to be greater than 1000")
return false
else
return true
end
end
function initialChecking()
if tX == "help" then
usage()
placingSetUp()
return false
elseif checkTurtleType() == false
or checkArguments() == false
or checkFuel() == false
or checkItems() == false
then
return false
else
return true
end
end
if initialChecking() == false then
return false
else
faceSouth()
end
bugs:
turtle no longer digs air to check if its a mining turtle. now it places the disk drive than dig it back.