#21
Posted 14 January 2013 - 12:50 AM
#22
Posted 14 January 2013 - 01:04 AM
#23
Posted 14 January 2013 - 01:14 AM
at line 114 it has a nil error but the only thing there is turtle.down()
if there is a block below the turtle it gives a nil error also but at line 107 another turtle.down()
rednet.open("right") rn = rednet.send fx = turtle.getItemCount(16) a = fx - 1 sleep(1) rn (base , "Connection established") sleep(1) rn (base , "getting fuel level") sleep(1) turtle.getFuelLevel() local f = turtle.getFuelLevel() sleep(1) rn (base , "Current fuel level is "..f.."" ) sleep(1) if f < 100 then turtle.getItemCount(16) rn (base , "current coal stack is") turtle.select(16) turtle.refuel(a) else rn (base , "Fuel levels are acceptable") sleep(1) end sleep(1) rn (base , "getting coal count") turtle.getItemCount(16) sleep(1) rn (base, "I have "..fx.." Coal") sleep(1) if fx < 64 then rn (base, "DANGER! Coal is low") os.reboot() else rn (base, "Coal storage is full") sleep(2) end sleep(1) rn (base , "comencing program") --=======comence mining=======-- z = 0 --===========fuel=============-- function fuel() print("1") f = turtle.getFuelLevel() if f < z + 10 then rn (base , "Danger! fuel levels low.") turtle.select(16) turtle.refuel(a) f = turtle.getFuelLevel() if f < z + 10 then rn (base , "Insuficient Coal, Returning.") home() end end end --=======return code==========-- function home() turtle.Up(z + 2) rn (base , "Mining Operation finished") os.shutdown() end --============value===========-- function value() if turtle.detect() == false then return false end for i = 1,3 do turtle.select(i) if turtle.compare() then return false end end end --============walls===========-- function walls() for j = 1,4 do if value() then turtle.dig() rn (base, "ORE!") else turtle.turnright() end end end --=============home===========-- function home() turtle.Up(z) rn (base , "Done, ready for pickup") os.shutdown() end --===========Dig Code=========-- function mine() print("1") fuel() print("2") turtle.detectDown() if turtle.detectDown() == true then turtle.digDown() turtle.detectDown() print("3") if turtle.detectDown() == true then rn (base , "I hit bedrock, Returning") home() else turtle.Down() print("4") walls() print("5") z = z + 1 end else turtle.Down() walls() z = z + 1 end end --===========start=========-- while true do mine() end
#24
Posted 14 January 2013 - 01:16 AM
#25
Posted 14 January 2013 - 01:20 AM
the monitor displays the message though. anyway im getting nils off of turtle.down now. i was so sure it was right
Quote
the program dosn't stall thoug it just terminates and back the os screen
#26
Posted 14 January 2013 - 01:28 AM
detsuo04, on 14 January 2013 - 01:20 AM, said:
From the wiki http://computercraft...iki/Rednet_(API)
"rednet.send(receiverID, message) — Sends a message to the computer using the opened sides. The receiver ID is the ID (number, not string) of the computer you're sending the message to. ID as nil will do the same as a broadcast."
#27
Posted 14 January 2013 - 01:37 AM
#28
Posted 14 January 2013 - 06:38 AM
i have poured over the code and as far as i can tel the code is good and turtle.down() is a command it should accept with no reason to return nil but i get a nil error on it in two places. any ideas would be awsome.
#29
Posted 14 January 2013 - 11:52 AM
#30
Posted 14 January 2013 - 11:57 AM
turtle.up()
turtle.down()
turtle.turnRight()
turtle.turnLeft()
notice where everything is capitalized. You often try to use turtle.Down() which wont work. Neither with turtle.turnright() and so on.
#31
Posted 14 January 2013 - 12:00 PM
for i = 1, z+2 do turtle.up() end
#32
Posted 14 January 2013 - 12:01 PM
crazyguymgd, on 14 January 2013 - 12:00 PM, said:
for i = 1, z+2 do turtle.up() end
#33
Posted 14 January 2013 - 12:04 PM
i am running it on a turtle yes. i have been fiddling for hours now and i think i have narrowed down to one last error before i have a working program.
Im using print # to find my error point and im getting a phantom end
I have been messing with it a bit so its a bit of a jumbled mess now. but for some reason the code returns 2222222 ect forever.
my nested ifs are to blame i think but i am having trouble narrowing down the problem.
EDIT: ok my downs where capped so yay thats one problem down. thanks for the help still the phantom end though
while true do print("2") f = turtle.getFuelLevel() if f < z + 10 then rn (base , "Danger! fuel levels low.") turtle.select(16) turtle.refuel(all) f = turtle.getFuelLevel() if f < z + 10 then rn (base , "Insuficient Coal, Returning.") home() else if turtle.detectDown() == true then turtle.digDown() turtle.detectDown() print("3") if turtle.detectDown() == true then rn (base , "I hit bedrock, Returning") home() else turtle.Down() walls() z = z + 1 end end end end
#34
Posted 14 January 2013 - 12:05 PM
while true do print("2")is the reason it prints 222222222 continuous... its an infinite loop and at the top you have print( "2" )
EDIT: More comments on how to fix it
while true do f = turtle.getFuelLevel() if f < z + 10 then rn (base , "Danger! fuel levels low.") turtle.select(16) turtle.refuel(all) -- refuel( all ) wouldn't work... use refuel() to 'refuel all' f = turtle.getFuelLevel() if f < z + 10 then rn (base , "Insuficient Coal, Returning.") home() else if turtle.detectDown() == true then -- == true is not needed here turtle.digDown() turtle.detectDown() -- this doesn't do anything... not needed print("3") -- another spamming print if turtle.detectDown() == true then -- == true is not needed here rn (base , "I hit bedrock, Returning") home() else turtle.down() -- still have a capital d walls() z = z + 1 end end end end end
Edited by TheOriginalBIT, 14 January 2013 - 12:10 PM.
#35
Posted 14 January 2013 - 12:08 PM
if i take out the while true do it just returns 2 then ends the program. so there is some reason it is shutting off after print 2
#36
Posted 14 January 2013 - 12:10 PM
#38
Posted 14 January 2013 - 12:15 PM
if condition true then
check condition 2 if condition true then
do this
if condition 1 not true do this
if condition 2 not true do ths
#39
Posted 14 January 2013 - 12:18 PM
detsuo04, on 14 January 2013 - 12:15 PM, said:
check condition 2 if condition true then
do this
if condition 1 not true do this
if condition 2 not true do ths
Not quite
if condition 1 then if condition 2 then do this else not condition 2 then end else not condition 1 then end
EDIT: And sorry I did miss nested ifs in the tips/explanation didnt i....
Edited by TheOriginalBIT, 14 January 2013 - 12:19 PM.
#40
Posted 14 January 2013 - 12:28 PM
z = 0 while true do print("2") f = turtle.getFuelLevel() if f < z + 10 then rn (base , "Danger! fuel levels low.") turtle.select(16) turtle.refuel() z = turtle.getFuelLevel() if f < z + 10 then rn (base , "Insuficient Coal, Returning.") home() end elseif turtle.detectDown() then turtle.digDown() --turtle.detectDown() print("3") if turtle.detectDown() then rn (base , "I hit bedrock, Returning") print("Your home function") --home() break -- to break out of the while loop end else turtle.down() print("your walls function") --walls() z = z + 1 end end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users