Program error.
detsuo04 14 Jan 2013
OH SNAP i think its working. will report back if it returns
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
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
detsuo04 14 Jan 2013
ok now i have fiddle and cleaned the best i can. now its telling me that i need to end the value() function but it sais that even if i add 20 ends to it.
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
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
crazyguymgd 14 Jan 2013
Here's your value function with proper indentation. As you can see, you're missing key ends (and you have unnecessary ends)
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
theoriginalbit 14 Jan 2013
Again with all the '== true' and '== false' ... while its not a 'bug' or an 'issue' with the code, it is bad coding practise to do this ... a function that returns a boolean or a boolean variable do not need an equality check in an if statement... if you want to check if a boolean variable/return value is true then just type the variable/return value ... if you want to check if its false then add a not before the variable/return value ... saying turtle.detect() == true is like making your while loop this, while true == true do ... its pointless, true will always equal true, just like not false will always equal true, and false will always equal false, and not true will always equal false ... does this make sense?
detsuo04 14 Jan 2013
OMG you are my hero it kept asking me for ends so i think at one point in a blind rage i just "Here take all the ends you can handle mua hahahaha !!! take them untill you explode!!!"
yes this section of coderesolved.
ill continue pooring over the
if argument then do error need more dos thing
Oh ok i see what that means now. using if argument then basicly means if argument is true then i understand
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
yes this section of code
ill continue pooring over the
if argument then do error need more dos thing
Quote
Again with all the '== true' and '== false' ...
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
crazyguymgd 14 Jan 2013
sorry, I missed that do,
for i = 1, 3 do if turtle.compare.......... end
theoriginalbit 14 Jan 2013
detsuo04, on 14 January 2013 - 01:32 PM, said:
Quote
Again with all the '== true' and '== false' ...
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:
Spoiler
theoriginalbit 14 Jan 2013
detsuo04 14 Jan 2013
I was going backwards there for a bit and hit my loop 222222 problem but i fixed that. now im cycling properly however
im having a problem where the value function only compares slot 1 despite having for i = 1 , 3 do
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
crazyguymgd 14 Jan 2013
when you return, that means stop the function right there. So here's what I would do:
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.
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.
detsuo04 14 Jan 2013
Awsome. i had just noticed in my program that i was returning false to to the walls function which would accept false as the argument. it wouldnt wate for value() to check slot 2 or 3
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
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
theoriginalbit 14 Jan 2013
Here is what I would do:
Its 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 the commented line, be how I have it typed there
Edited by TheOriginalBIT, 14 January 2013 - 03:14 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.
crazyguymgd 14 Jan 2013
TheOriginalBIT, on 14 January 2013 - 03:07 PM, said:
Here is what I would do:
also just a question, shouldn't
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
theoriginalbit 14 Jan 2013
crazyguymgd, on 14 January 2013 - 03:11 PM, said:
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
Oops that change to the code was a last minute edit, forgot that I said that
crazyguymgd 14 Jan 2013
Ahh and yes it should be if turtle.compare() then.... without the not. thanks for the catch
detsuo04 14 Jan 2013
well in slots 1 2 and 3 i have dirt gravel and stone respectivly. so it checks that its not thoes before it mines it.
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.
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