Jump to content




Return to spawnpoint


2 replies to this topic

#1 DaveyBeer1999

  • Members
  • 7 posts
  • LocationNetherlands

Posted 25 July 2020 - 10:47 PM

Hi I'm not sure how to make a turtle return to a spawnpoint,
Do you use a local count?
I used computercraft allot in the past but I never tried making it return to a startpoint... any tips on how?

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 July 2020 - 11:05 PM

Well, the most straightforward method would be to record the movements made from the "starting point" and then reverse them to go back to it. Of course, this misses opportunities for optimization, such as skipping loops in the path. You could make replacement functions for the turtle movement commands that add the movements to a list, saves the list as a file somehow, and then provide a new function to work back through the list.

Something like the Location-Aware Movement API may be able to do all of this for you already, though--and replicating that level of effort on persistent/correct/complete recording of movements would be difficult.

#3 DaveyBeer1999

  • Members
  • 7 posts
  • LocationNetherlands

Posted 26 July 2020 - 01:21 PM

Well right now I got my code to work to go forward and Refuel but as soon as i add the go back to start it refuels but instead of going forward its going backwards and skips the entire forward part.
--Fuel level
term.setTextColor(colors.red)
print("Fuel Level = ".. turtle.getFuelLevel() )
sleep(2)
--Telling to Refuel
term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(colors.lime)
  print("Lets Refuel")
--Length
sleep(1)
local length = 1
term.write("How far to go? ")
length = read()
print("Distance set: ".. length)
sleep(1)
--Fueling
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.yellow)
term.write("Starting to refuel going #".. length)
--Getting Lava
for i = 1, length do
turtle.select(1)
  print("selected slot 1!")
  turtle.placeDown()
  turtle.refuel()
if turtle.forward() do
  print("Moving")
else
  turtle.dig()
  turtle.forward()
--Return to start
print("Returning to start!")
for i = 1, length do
turtle.back()
end
I'm making it print so much to see where the code is and what it is checking

Edited by DaveyBeer1999, 26 July 2020 - 01:22 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users