- ComputerCraft | Programmable Computers for Minecraft
- → Zachaq's Content
Zachaq's Content
There have been 7 items by Zachaq (Search limited from 30-March 23)
#3276 [lua] [turtles] turtle.place() quirk
Posted by Zachaq on 07 March 2012 - 08:26 PM in Ask a Pro
I've been trying to place a torch with turtle.placeUp() from slot 4, and I've noticed that when there isn't a valid place for a torch, instead of returning false, it simply pulls a block, in my case from slot 1, and places that instead. My question is, is there a way to get around this that doesn't involve moving the turtle, or am I out of luck?
#2903 Error I can't figure out
Posted by Zachaq on 04 March 2012 - 08:05 PM in Ask a Pro
MysticT, on 04 March 2012 - 01:43 PM, said:
Well, the problem is that you forgot the parentheses after the turtle.forward call, it should be:
... turtle.forward() if ...That's it, the if is ok />
*checks code*
Sure enough...... Why was that making the if line error though?
Another thing I was wondering about, my original idea for this was just to have it tunnel as far as you want it to, similiar to the Tunnel program. I had it put down chunkloaders (from Additional pipes for Build Craft) every so often, so it could keep going even when no one was around. However I found that even with those chunkloaders, the turtle would restart when the player leaves the area. This is on SMP. Is that intended behavior?
#2751 Error I can't figure out
Posted by Zachaq on 04 March 2012 - 03:03 AM in Ask a Pro
I've been playing with CC a few days, I haven't gotten into programming before, so I'm learning as I go. I'm trying to use an if statement, but it keeps returning an '=' expected error. I know what this means, and I've tried fixing it, but nothing I do to it helps. I even tried it alone, without the function it's in, and it seemed to work okay. Hopefully it isn't something too obvious, but here it is:
Also, if anyone would like to read over the rest of the code, I would appreciate the insight. It's a program that digs a 2x2 tunnel, places Industrial Craft miners with a chest every ninth block, puts down chunkloaders every so often, and also puts torches on the wall, if there is a wall. Just a note, I know I should use local variables vs globals, but I can't make them work either, some tips on that would be welcome.
I tried to reindent it after copying, but I promise the orignal was formatted better
function placetorch() --puts a torch (slot 4) above the turtle turtle.turnRight() turtle.forward() turtle.up() turtle.turnRight() turtle.turnRight() turtle.forward if turtle.detect() == true then --Error on this line. Not sure why. turtle.back() turtle.select(4) turtle.place() turtle.down() turtle.forward() turtle.turnRight() else turtle.down() turtle.turnRight() end end
Also, if anyone would like to read over the rest of the code, I would appreciate the insight. It's a program that digs a 2x2 tunnel, places Industrial Craft miners with a chest every ninth block, puts down chunkloaders every so often, and also puts torches on the wall, if there is a wall. Just a note, I know I should use local variables vs globals, but I can't make them work either, some tips on that would be welcome.
function check() -- checks for a block and digs it. Works with sand and gravel while turtle.detect() == true do sleep(1) turtle.dig(1) sleep(1) end end function dig() -- tunnels a 2x2x2 cube forward check() turtle.forward(1) turtle.turnRight(1) check() turtle.digUp(1) turtle.forward(1) turtle.digUp(1) turtle.turnLeft(1) check() turtle.forward(1) turtle.digUp(1) turtle.turnLeft(1) check() turtle.forward(1) turtle.digUp(1) turtle.turnRight(1) end function checkminer() --are the miners there and in the right slot? if turtle.getItemCount(1) > 0 and turtle.getItemCount(2) > 0 then hasminer = true else hasminer = false end end function placetorch() --puts a torch (slot 4) above the turtle turtle.turnRight() turtle.forward() turtle.up() turtle.turnRight() turtle.turnRight() turtle.forward if turtle.detect() == true then --Error on this line. Not sure why. turtle.back() turtle.select(4) turtle.place() turtle.down() turtle.forward() turtle.turnRight() else turtle.down() turtle.turnRight() end end function cycle() -- digs 9 length tunnel and places one set of miners, and a torch on the wall dig() dig() placetorch() dig() dig() dig() turtle.turnLeft() turtle.turnLeft() turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.select(1) turtle.place(1) turtle.back() turtle.select(2) turtle.place(1) turtle.turnLeft(1) turtle.turnLeft(1) turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.forward() end function chunk() -- drops a chunkloader (slot 3) behind it turtle.turnLeft(1) turtle.turnLeft(1) turtle.select(3) turtle.place(1) turtle.turnLeft(1) turtle.turnLeft(1) end function checkinv() -- dumps inventory if it is full if turtle.getItemCount(5) >= 32 then turtle.select(5) turtle.drop(5) end if turtle.getItemCount(6) >= 32 then turtle.select(6) turtle.drop(6) end if turtle.getItemCount(7) >= 32 then turtle.select(7) turtle.drop(7) end if turtle.getItemCount(8) >= 32 then turtle.select(8) turtle.drop(8) end if turtle.getItemCount(9) >= 32 then turtle.select(9) turtle.drop(9) end end term.clear() term.setCursorPos(1,1) sleep(1) print("Mining Sequence initiated.") sleep(1) print("Please check that the Bot is exactly 1 block behind where you want the first miner to go, and that it is facing the direction you want it to mine") sleep(1) word = nil while word == nil do --surely there is a better way to do this bit print("Enter 'confirm', without the quotes, to continue") local word = io.read() if word == ("confirm") then term.clear() term.setCursorPos(1,1) print("Now make sure that there are miners in the top left slot, chests in the top middle slot, chunkloaders in the top right slot, and torches in the middle left slot.") sleep(1) else term.clear() term.setCursorPos(1,1) end end word2 = nil while word2 == nil do print("Enter 'confirm', without the quotes, to continue") local word2 = io.read() if word2 == ("confirm") then term.clear() term.setCursorPos(1,1) print("Confirmation successful. Stand back, and let the Bot do its thing. Be sure to report any unusual behavior.") sleep(5) else term.clear() term.setCursorPos(1,1) end end cyclenumber = 0 --controls chunk drops checkminer() if hasminer == false then print("Out of Miners, stopping.") end while hasminer == true do -- the looper to keep this going cycle() checkminer() if hasminer == false then term.clear() term.setCursorPos(1,1) print("Out of Miners, stopping.") end checkinv() cyclenumber = cyclenumber + 1 if cyclenumber == 2 then chunk() cyclenumber = 0 end end
I tried to reindent it after copying, but I promise the orignal was formatted better
- ComputerCraft | Programmable Computers for Minecraft
- → Zachaq's Content