Question about Turtles

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
Changed the second if to reflect "until turtle.getFuelLevel() >= 70 then" and removed the first repeat and it still throws up the "unexpected symbol" error.

Code:
local num = 30
local delay = 2
num = num -1
redstone.setOutput("left", true)
for i = 1, num do
  sleep(delay)
  turtle.forward()
end
sleep(delay)
redstone.setOutput("left", false)
for i = 1, num do
  turtle.back()
end
 
print "Checking fuel..."
local i = 1
if turtle.getFuelLevel() < 40 then
  turtle.turnRight()
  turtle.forward()
  turtle.turnLeft()
  print("refueling...")
  local x,y = term.getCursorPos()
  repeat
  term.clearLine()
  term.setCursorPos(1,y)
  write("Fuel Level: "..turtle.getFuelLevel())
  sleep(0.05)
  i = i + 1
  until turtle.getFuelLevel() >= 70 then
  turtle.turnRight()
  turtle.back()
  turtle.turnLeft()
  sleep(delay)
else
print("No fuel necessary")
end
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
Thank you, that did it. Running a few more tests to see if it works with no problems.

if I wanted to start with a clear display every time the turtle runs, what line do I have to add?
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
OK, thanks guys. You help was appreciated. However, I ran into a problem.

This is the final draft of the code:
Code:
term.clear()
term.setCursorPos(1,1)
local num = 34
local delay = 2
num = num -1
redstone.setOutput("left", true)
for i = 1, num do
  sleep(delay)
  turtle.forward()
end
sleep(delay)
redstone.setOutput("left", false)
for i = 1, num do
  turtle.back()
end
 
print "Checking fuel..."
local i = 1
if turtle.getFuelLevel() < 40 then
  turtle.back()
  print("refueling...")
  local x,y = term.getCursorPos()
  repeat
  term.clearLine()
  term.setCursorPos(1,y)
  write("Fuel Level: "..turtle.getFuelLevel())
  sleep(0.05)
  i = i + 1
  until turtle.getFuelLevel() >= 70
  turtle.forward() 
  sleep(delay)
else
print("No fuel necessary")
end

PROBLEM: What I need to do is have the turtle take one move forward WITHOUT a delay and then have the rest delayed. the non-delayed move has to count against the total amount of moves the turtle can go before reaching its destination.

Is this possible?
 

Pinkishu

New Member
Jul 29, 2019
143
0
0
Well you could either do something like

Code:
turtle.forward()
for i=1,num-1 do
  sleep(delay)
  turtle.forward()
end

or maybe

Code:
for i=1,num do
  if i ~= 1 then sleep(delay) end
  turtle.forward()
?
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
First one helped, thanks. But having a problem with the charge station, it stops functioning when I log off and back on again. Is there a way to fix this?
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
How do you get it to work again. I must admit I have never used one before so I don't really know how they work.
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
Just place one, power it with a solar panel (either directly linked or via cable) and have the turtle either placed at the spot with the black dot or have it move there. But I found they're buggered as they will stop charging as soon as you log off and then on again.

EDIT: yup, completely buggered as I can't even get the right facing with a block breaker/deployer combo.
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
That sucks, maybe its a bug? If you want to you can fuel your turtles with charcoal or anything that burns in a furnace (give or take). If you place a chest that gets supplied with fuel below the turtle's starting position (or above whatever's practical), you can interact with the chest to pull a stack of out with turtle.suck() or turtle.suckUp() / turtle.suckDown(). 64 charcoal or coal will yield 5120 movement points. Alternatively, if you want to utilise the EU setup you have you could use batteries to recharge. One EU = 1 movement point I think. if you want to drop an empty battery back into a batbox or mfe use turtle.drop() while facing it. It might be that you can only drop them in via the top face of the batbox though.
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
So basically, it's buggered as hell and I should stick to coal. How much fuel does one coal give?
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
Thanks, that helped. But ran into more problems when trying to convert the turtle to use coal.

Code:
term.clear()
term.setCursorPos(1,1)
local num = 34
local delay = 2
num = num -1
redstone.setOutput("left", true)
turtle.forward()
for i=1,num-1 do
  sleep(delay)
  turtle.forward()
end
sleep(delay)
redstone.setOutput("left", false)
for i = 1, num do
  turtle.back()
end
 
print "Checking fuel..."
if turtle.getFuelLevel() <= 66 then
  turtle.back()
  print("refueling...")
  local x,y = term.getCursorPos()
  term.clearLine()
  term.setCursorPos(1,y)
  sleep(0.05)
  turtle.select(1)
  turtle.getItemCount(1)
    if turtle.getItemCount == 0 then
      turtle.suckUp(1)
    end
  turtle.refuel(1)
  turtle.getfuelLevel()
  write("Fuel Level: "..turtle.getFuelLevel())
  turtle.forward()
  sleep(delay)
else
print("No fuel necessary")
end

It would precede to carry out its instructions but when it went back to get some coal, I always get an "attempt to call nil" error and it wouldn't suck up anything from a chest above it. Also, forgot to mention that the last movement shouldn't be delayed as it switches machine phases.
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
inside the if statement you forgot to put the brackets on turtle.getItemCount(n). Attempt to call nil means the program failed because it was trying to run a command that didn't exist, whether it is one of your own functions or something in basic computercraft or Lua. It usually happens because of a spelling mistake.
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
OK, that worked. But how do I get the last movement to not be delayed?

I tried this:
Code:
for i=1,num-1 do
  if num == 1 then
    turtle.forward()
  end
  sleep(delay)
  turtle.forward()
end

It didn't work.

EDIT: had to change the 1 to a 2, but when it reached to end to take coal, I got an "Expected Number" error.

EDIT 2: Saw my problem, forgot a number. Testing now.
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
Can you remind me why the for loop goes up to num-1 again please?

Also within the for loop num doesn't change only i does so if you want something to happen when i = something but not something else you need to refer to i.

PS: If the reason the for loop goes up to num-1 is because you didn't want a delay in the first movement to then look inside the spoiler

This might work

Code:
for i= 1,num do
  if i >= 2 and i <= (num-1) then
      sleep(delay)
  end
  turtle.forward()
end
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
The loop starts at num = -1 because it's one block before the first piston it has to activate. That piston and all others must be delayed for a total of 16 seconds (testing with a delay of 2 seconds to see if everything works). When it goes past the last piston, it has to just send a redstone pulse before heading back to shut off the build process. If I got the timing wrong between signaling the end of Phase 2 and shutting down the build process, I might have to use a turtle teleporter.
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
Are the Turtle Teleport blocks as buggered as the charge stations? I'm trying to get the turtle to teleport and I linked them, but it won't teleport.

Code:
term.clear()
term.setCursorPos(1,1)
local num = 34
local delay = 2
num = num -1
redstone.setOutput("front", true)
redstone.setOutput("left", true)
turtle.forward()
for i=1,num-1 do
  if num == 2 then
    turtle.forward()
  end
  sleep(delay)
  turtle.forward()
end
 
redstone.setOutput("left", false)
sleep(0.5)
redstone.setOutput("front", false)
sleep(6.5)
peripheral.call("bottom","teleport")
 
print "Checking fuel..."
local i = 1
if turtle.getFuelLevel() < 40 then
  turtle.back()
  print("refueling...")
  local x,y = term.getCursorPos()
  repeat
  term.clearLine()
  term.setCursorPos(1,y)
  write("Fuel Level: "..turtle.getFuelLevel())
  sleep(0.05)
  i = i + 1
  until turtle.getFuelLevel() >= 105
  turtle.forward()
  sleep(delay)
else
print("No fuel necessary")
end
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
I have never used the teleport thing before but I think I know what the problem is. I don't think you are interacting with the teleporter properly. I can't be sure but this might be what you need to do. First of all right at the top of your code write this line.

local tport = peripheral.wrap("bottom") -- assuming the teleporter is below. Also you can change tport to anything you want.

In order to interact with a peripheral you need to wrap it. You can use peripheral.call() too but I find that it is much clunkier. The advantage of wrapping it is that you can call its functions with the variable you gave it. so when you want to teleport you can do this

tport.teleport()

At least I think that is the correct command for the teleporter. Direwolf20 uses turtle teleporters for one of the quarry episodes in his season 5 lets play, that might give you better information.

Are you teleporting to your fuel zone btw? Because teleporting is quite fuel hungry.

EDIT: variable = peripheral.wrap(side) works for all othr peripherals too and follows the same format. You can use it for monitors, printers and much else besides
 

Furious1964

Well-Known Member
Nov 10, 2012
1,436
70
63
Yes. After it finishes its job, it waits 6.5 seconds and then teleports back to its starting position.

And no, it's still not working after I made those changes. I linked the teleporters and put the proper coding, but it skips the teleport completely and goes on to checking fuel level.