#41
Posted 14 January 2013 - 12:35 PM
ok so sadly it dosnt fully work.
it goes down to bed rock mining the block below it each stem. it also looks at the walls around it each step but it ignores all and just goes to bedrock.
when it hits bedrock it fails to return. still looking over the code
#42
Posted 14 January 2013 - 01:20 PM
also sais something is wrong with my else statment in value() eof expected?
And it sais do expected on lines where there already is a do statment
rednet.open("right") rn = rednet.send fx = turtle.getItemCount(16) a = fx - 1 sleep(1) base = 13 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 --=======return code==========-- function home() for n = 1, z +2 do turtle.up() end rn (base , "Mining Operation finished") os.shutdown() end --============value===========-- function value() if turtle.detect() == false then return false end else for i = 1 , 3 if turtle.compareTo(i) == true then return false end else return true end end --============walls===========-- function walls() j = 1 for j = 1,4 do if value() == true then do turtle.dig() rn (base, "ORE!") end else turtle.turnRight() j = j + 1 end end --=============home===========-- function home() for i = 1 , z do turtle.up() rn (base , "Done, ready for pickup") os.shutdown() end end --===========Dig Code=========-- while true do print("2") f = turtle.getFuelLevel() if f < z + 10 then do rn (base , "Danger! fuel levels low.") turtle.select(16) turtle.refuel(all) f = turtle.getFuelLevel() if f < z + 10 then do rn (base , "Insuficient Coal, Returning.") home() end end end else if turtle.detectDown() == true then do turtle.digDown() turtle.detectDown() print("3") if turtle.detectDown() == true then do rn (base , "I hit bedrock, Returning") home() end end end else do turtle.down() rn (base , "Nothing on level "..z.."next") walls() z = z + 1 end end end end
#43
Posted 14 January 2013 - 01:24 PM
function value() if turtle.detect() == false then return false end else for i = 1 , 3 if turtle.compareTo(i) == true then return false end else return true end endAnd here's the correct way to use the if's, else's and ends
function value() if turtle.detect() == false then return false else for i = 1 , 3 if turtle.compareTo(i) == true then return false else return true end end end end
#44
Posted 14 January 2013 - 01:29 PM
#45
Posted 14 January 2013 - 01:32 PM
yes this section of code
ill continue pooring over the
if argument then do error need more dos thing
Quote
EDIT: ok so it still wants there to be a do after each then. if i put a do there it sais i need more ends. when i add the ends it wants more do's
function value() if not turtle.detect() then return false else for i = 1 , 3 if turtle.compareTo(i) then return false else return true end end end end
#46
Posted 14 January 2013 - 01:54 PM
for i = 1, 3 do if turtle.compare.......... end
#47
Posted 14 January 2013 - 01:55 PM
#48
Posted 14 January 2013 - 02:01 PM
#49
Posted 14 January 2013 - 02:11 PM
detsuo04, on 14 January 2013 - 01:32 PM, said:
Quote
if you have say some input variable and you want to check the user types hello you have to do this
someVariable = read() if someVariable == "hello" thenthis is because someVariable is not a boolean but is a string, so we need to test equality
Pro tip:
#50
Posted 14 January 2013 - 02:13 PM
dam facebook
#52
Posted 14 January 2013 - 02:56 PM
im having a problem where the value function only compares slot 1 despite having for i = 1 , 3 do
function value() if not turtle.detect() then return false else for i = 1 , 3 do print("comparing "..i.." now") turtle.select(i) if turtle.compare() then return false else return true end end end end
#53
Posted 14 January 2013 - 03:01 PM
function value() if not turtle.detect() then return false else for i = 1 , 3 do print("comparing "..i.." now") turtle.select(i) if not turtle.compare() then return true end end return false end end
As you can see, it will return true if it finds something at i, and returns false only if the for loop exits, and it hasn't returned true yet.
However, this might cause a problem if there is something at 1 and 2 because it'll return true at 1, then skip 2 because it returned.
#54
Posted 14 January 2013 - 03:06 PM
Edit:
Ok i just danced a jig when lil hal grabed the wood planking of my floore and proclaimed triumphantly "ORE!"
edit 2:
though he still refuses to return up
#55
Posted 14 January 2013 - 03:07 PM
function value() if not turtle.detect() then return false end for i = 1 , 3 do print("comparing "..i.." now") turtle.select(i) if turtle.compare() then -- I'm assuming this was meant to be when it finds something return true end end end return false end
also just a question, shouldn't the commented line, be how I have it typed there
Edited by TheOriginalBIT, 14 January 2013 - 03:14 PM.
#56
Posted 14 January 2013 - 03:11 PM
TheOriginalBIT, on 14 January 2013 - 03:07 PM, said:
function value() if not turtle.detect() then return false end for i = 1 , 3 do print("comparing "..i.." now") turtle.select(i) if turtle.compare() then -- I'm assuming this was meant to be when it finds something return true end end end return false endIts not any different logically, but it has a slightly better flow, then also if you decide to add anything else in later you wont forget to put return false in at the end of the function...
also just a question, shouldn't
How is it not different logically? Originally, if the compare with the block at slot 1 was false, he would return false and never check slot 2 or 3. This checks slots 2 and 3 if 1 fails. Which is differentt
#57
Posted 14 January 2013 - 03:13 PM
crazyguymgd, on 14 January 2013 - 03:11 PM, said:
Oops that change to the code was a last minute edit, forgot that I said that
#58
Posted 14 January 2013 - 03:18 PM
#59
Posted 14 January 2013 - 03:32 PM
i just tested my program and it worked 100%
he mines down checking all his sides as he goes looking for not stone dirt or gravel, when he finds it he mines that.
later i plan on adding a location ticker setup like i did with the z axis so he can venure away from the mine shaft to get an entire veign of ore.
here is the finished code.
rednet.open("right") rn = rednet.send fx = turtle.getItemCount(16) a = fx - 1 sleep(1) base = 13 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 --=======return code==========-- function home() n = 0 while n ~= z do turtle.up() n = n + 1 end rn (base , "Mining Operation finished") rn (base , "ready for Pickup") os.shutdown() end --============value===========-- function value() ts = turtle.select tc = turtle.compare if not turtle.detect() then return false else ts(1) b = turtle.compare() ts(2) n = turtle.compare() ts(3) m = turtle.compare() if m or n or b then return false else return true end end end --============walls===========-- function walls() for j = 1,4 do print("value function") if value() then turtle.dig() rn (base, "ore collected at "..z.." ") else turtle.turnRight() end end end --===========Dig Code=========-- 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() rn (base , "Nothing on "..z.." moving down") print("your walls function") walls() z = z + 1 end end
#60
Posted 14 January 2013 - 03:35 PM
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users