20 posts
Posted 03 January 2013 - 05:57 AM
Back to askin a pro!
My torch placing function does not work now, I fixed the arithmetic sub problem!
-- Variables
tArgs = { ... }
local distance = (tArgs[1])
local togo = tonumber ( distance )
local num = 0
-- Functions
function torch ()
if num == 9 then
turtle.select(15)
turtle.place()
turtle.forward()
num = 0
end
end
function layer ()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.up()
turtle.dig()
turtle.up()
turtle.dig()
turtle.turnLeft()
turtle.down()
turtle.down()
end
function tfuel(amount)
local fuelLevel = turtle.getFuelLevel()
if fuelLevel < 50 then
turtle.select(16)
turtle.refuel(amount)
turtle.select(1)
end
end
--Main Script
print ("this will dig a 3x3 tunnel for a specified amount of blocks")
print("put coal in slot 16 (bottom right) so the turtle will fuel it self")
print("Put torches in slot 15 so the turtle will light things up")
print("To verify, you want the turtle to dig" ..togo "blocks")
print("Press ENTER to begin")
local sEvent, param = os.pullEvent("key")
if sEvent == "key" then
if param == 28 then
repeat
tfuel(1)
torch()
num = num + 1
layer ()
togo = togo - 1
until togo == 0
end
end
I hope it's an easy fix!
Thanks
-Birdgeek
1054 posts
Posted 03 January 2013 - 06:09 AM
The full error message is important, it contains the line at which the error occurred. My simple guess, have you actually given a number as parameter to the program?
20 posts
Posted 03 January 2013 - 06:23 AM
Full error is
tunnelDigger:7: attempt to perform arithmetix__sub on a numb and nil
This happens when I enter both 5 and 25
200 posts
Location
Scotland
Posted 03 January 2013 - 06:25 AM
line 6
you have - Functions instead of – Functions
200 posts
Location
Scotland
Posted 03 January 2013 - 06:28 AM
Also line 54 should be:
print("To verify, you want the turtle to dig" ..togo.. "blocks")
instead of
print("To verify, you want the turtle to dig" ..togo "blocks")
20 posts
Posted 03 January 2013 - 07:28 AM
line 6
you have - Functions instead of – Functions
Simple mistakes changes everything!
Thanks!
And now the torch placing function does not work.
Any clue?
2088 posts
Location
South Africa
Posted 03 January 2013 - 08:00 AM
No reason why it shouldn't work?
Did you maybe forget to place torches in slot 15? :P/>
Change the repeat loop to this and check if it prints anything
repeat
tfuel(1)
if num == 9 then
turtle.select(15)
turtle.place()
turtle.forward()
num = 0
print("Placed torch!")
else
num = num + 1
end
layer ()
togo = togo - 1
until togo == 0
20 posts
Posted 03 January 2013 - 08:35 AM
No reason why it shouldn't work?
Did you maybe forget to place torches in slot 15? :P/>
Change the repeat loop to this and check if it prints anything
repeat
tfuel(1)
if num == 9 then
turtle.select(15)
turtle.place()
turtle.forward()
num = 0
print("Placed torch!")
else
num = num + 1
end
layer ()
togo = togo - 1
until togo == 0
What happens is he places the torch and then breaks it right away
Here is my updated code
-- Variables
tArgs = { ... }
local distance = (tArgs[1])
local togo = tonumber ( distance )
local num = 0
-- Functions
function torch ()
if num == 9 then
turtle.select(15)
turtle.dig()
turtle.place()
turtle.forward()
turtle.select(1)
num = 0
end
end
function layer ()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.up()
turtle.dig()
turtle.up()
turtle.dig()
turtle.turnLeft()
turtle.down()
turtle.down()
end
function tfuel(amount)
local fuelLevel = turtle.getFuelLevel()
if fuelLevel < 50 then
turtle.select(16)
turtle.refuel(amount)
turtle.select(1)
end
end
--Main Script
print ("this will dig a 3x3 tunnel for a specified amount of blocks")
print("put coal in slot 16 (bottom right) so the turtle will fuel it self")
print("Put torches in slot 15 so the turtle will light things up")
print("To verify, you want the turtle to dig " ..togo.. " blocks")
print("Press ENTER to begin")
local sEvent, param = os.pullEvent("key")
if sEvent == "key" then
if param == 28 then
repeat
tfuel(1)
torch()
num = num + 1
print (num)
layer ()
togo = togo - 1
until togo == 0
end
end
2088 posts
Location
South Africa
Posted 03 January 2013 - 09:42 AM
It's because layer() is called after torch and the first command of layer() is turtle.dig(), so it places and then digs.
Make the torch be placed on the right or left:
function torch ()
if num == 9 then
turtle.select(15)
turtle.dig()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.select(1)
num = 0
end
end
20 posts
Posted 03 January 2013 - 11:43 AM
It's because layer() is called after torch and the first command of layer() is turtle.dig(), so it places and then digs.
Make the torch be placed on the right or left:
function torch ()
if num == 9 then
turtle.select(15)
turtle.dig()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.select(1)
num = 0
end
end
I fixed it :)/>
Thanks for the help :)/>