Jump to content




Coordinate system


  • You cannot reply to this topic
4 replies to this topic

#1 Apfeldstrudel

  • Members
  • 161 posts

Posted 02 July 2013 - 08:42 AM

I made a mining turtle months ago and uploaded it here, it keeps trak of its coordinates using the file system.

This is part of my code

while turtle.forward() == false do
  turtle.attack()
  turtle.dig()
end
Increment variables depending on direction
save()
the thing is that if the chunk unloads when it is moving it doesent do the coordinate thing.

Fix? Maybe using the paralell API?

#2 CoderPuppy

  • Members
  • 121 posts

Posted 02 July 2013 - 09:04 AM

You should look at this thread for reloading coordinates: http://www.computerc...s-world-reload/

#3 Apfeldstrudel

  • Members
  • 161 posts

Posted 02 July 2013 - 09:24 AM

Wouldnt that break if it moves up or down?

#4 Apfeldstrudel

  • Members
  • 161 posts

Posted 02 July 2013 - 09:33 AM

I suppose a complete rewrite of my turtle is coming up now :D

#5 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 02 July 2013 - 09:37 AM

You know you can be very, very sneaky with this. I mean, you can 'rewrite' the turtle.<direction> functions!
local turtleUp = turtle.up
turtle.up = function()
    --# Do stuff, the coords system in this case
    turtleUp()
end
--# A rough example (nothing to due with coords, just showcase what you can do with it)
local turtleUp = turtle.up
turtle.up = function( time )
    if type( tonumber(time) ) ~= "number" then error("Number expected, got " .. type( tonumber(time) ), 2 ) end
    for i = 1, tonumber(time) do
        turtleUp()
    end
end

But, what if another program uses turtle.up()? Well, we change it back to the original when the program quits:
turtle.up = turtleUp

After you have done that, you can use all programs just like you would normally. Also a tip:
local turtleUp = turtle.up
turtle.up = function()
   if turtleUp() then
      --# only do it when we actually moved! Very important!
   end
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users