Jump to content




New method for turtle API - direction.


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

#1 CrazyCatLady

  • New Members
  • 2 posts

Posted 21 October 2012 - 07:07 PM

I tried to search for it and didn't find such a suggestion. I feel one simple method added to the turtle API would greatly improve it. It should return the turtle's current direction (where is it facing: north, south, east or west).

#2 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 21 October 2012 - 07:22 PM

This could be made to altering the turnLeft and turnRight function.

#3 Sebra

  • Members
  • 726 posts

Posted 21 October 2012 - 07:25 PM

Denied by Dan200.
Use some peripheral instead or setup a GPS network.

#4 slay_mithos

  • New Members
  • 22 posts

Posted 21 October 2012 - 08:26 PM

GPS, yeah, that or tracking your every turn.

It is important to note that gps can't directly give you the direction, and that could be where it is added, but I guess it's still a no.

#5 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 21 October 2012 - 08:41 PM

Unless you have a source for that denial, don't post.

#6 ChunLing

  • Members
  • 2,027 posts

Posted 21 October 2012 - 10:51 PM

You can simply move forward one and check to see which direction you moved, i.e.:
x1,y1,z1 = gps.locate(2,true)
turtle.forward()
if x1 then --there is a GPS system
	   x2,_,z2 = gps.locate(2)
	   x2,z2 = x2-x1,z2-z1
end
x2,z2 now contain which axis you moved on and which direction.

There is also at least one peripheral mod that lets you craft a compass turtle...I may think it's not very useful but the option is there.

Edited by ChunLing, 21 October 2012 - 10:52 PM.


#7 matejdro

  • Members
  • 324 posts

Posted 22 October 2012 - 03:33 PM

If you really want it - there is compass turtle peripheral.

Otherwise, it's trivial to set up two alternate right and left functions that remember how many times your turtle turned so you can always get the direction. Only problem might be that this system would be relative to turtle's first direction when you placed it down.

#8 CrazyCatLady

  • New Members
  • 2 posts

Posted 22 October 2012 - 07:13 PM

The problem is that CC does not keep its state, so after quiting MC and starting it again all programs restart. If a program left a turtle in some weird position while quiting MC, this turtle may do some unplanned things after MC starts again (I use autostart with my turtles).

And it's not always possible to move a turtle... Not to mention that I have to setup a gps network to have a workaround for something that would not bother me if CC was keeping it's state and would continue programs :)/>

Thanks for the tip about the compass peripheral - I'm gonna look into it.

Edit: Not that useful, I'm afraid. I need every kind of turtle to be able to tell direction, not just one specific kind.

#9 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 22 October 2012 - 07:53 PM

View PostCrazyCatLady, on 22 October 2012 - 07:13 PM, said:

The problem is that CC does not keep its state, so after quiting MC and starting it again all programs restart. If a program left a turtle in some weird position while quiting MC, this turtle may do some unplanned things after MC starts again (I use autostart with my turtles).

And it's not always possible to move a turtle... Not to mention that I have to setup a gps network to have a workaround for something that would not bother me if CC was keeping it's state and would continue programs :)/>

Thanks for the tip about the compass peripheral - I'm gonna look into it.

Edit: Not that useful, I'm afraid. I need every kind of turtle to be able to tell direction, not just one specific kind.

Then save the direction to disk whenever you rotate. However I'll see if we can add it.

Persistence will be coming to CC eventually.

#10 matejdro

  • Members
  • 324 posts

Posted 22 October 2012 - 07:55 PM

It's not that simple. Sometimes chunk is unloaded in between saving and rotating. For example, I save new direction to disk and then rotate. However, chunk unloads right before rotating meaning that my turtle thinks he rotated but he did not.

It might seem like a slim chance but this happens quite frequently for me. Not so with rotating, but with moving (save coordinates and then move). That is why none of my moving-related turtles are autostarted.

AFAIK nearly every turtle can be combined with compass peripheral?

#11 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 22 October 2012 - 08:20 PM

View Postmatejdro, on 22 October 2012 - 07:55 PM, said:

It's not that simple. Sometimes chunk is unloaded in between saving and rotating. For example, I save new direction to disk and then rotate. However, chunk unloads right before rotating meaning that my turtle thinks he rotated but he did not.

It might seem like a slim chance but this happens quite frequently for me. Not so with rotating, but with moving (save coordinates and then move). That is why none of my moving-related turtles are autostarted.

AFAIK nearly every turtle can be combined with compass peripheral?

Then only save after it has moved?

#12 matejdro

  • Members
  • 324 posts

Posted 22 October 2012 - 08:22 PM

Then turtle moves and after move it saves. But again chunk might unload after moving but before saving.

#13 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 22 October 2012 - 09:03 PM

View Postmatejdro, on 22 October 2012 - 08:22 PM, said:

Then turtle moves and after move it saves. But again chunk might unload after moving but before saving.

Possible but less likely. One easier way to be sure is to queue the turtle movement using turtle.native.turnLeft().

#14 matejdro

  • Members
  • 324 posts

Posted 22 October 2012 - 09:08 PM

Turtle.native?

#15 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 22 October 2012 - 09:15 PM

View Postmatejdro, on 22 October 2012 - 09:08 PM, said:

Turtle.native?

Yep - calls the functions without waiting for a response (although you could handle the success or failure event yourself). I agree it isn't ideal though and I'll look into it.

#16 ChunLing

  • Members
  • 2,027 posts

Posted 22 October 2012 - 11:50 PM

I'd rather have persistence done sooner than distract you from working on it. I've been able to get all the saving and stuff I need, but persistence would still be nice.

#17 matejdro

  • Members
  • 324 posts

Posted 24 October 2012 - 03:28 PM

Sounds interesting. But how do you know when turtle moved and if moved successfully?

#18 GopherAtl

  • Members
  • 888 posts

Posted 24 October 2012 - 03:34 PM

just saving after instead of before eliminated the vast majority of failures when I tested this in turtlex. Saving before, any unload while it was running a program was almost always off by the last move or turn that was unfinished, while saving after very rarely had any issue. Of course, very rarely is not never, but it beats the hell out of almost always.

#19 matejdro

  • Members
  • 324 posts

Posted 24 October 2012 - 03:53 PM

I'm actually saving it after. But I still get issues quite regularly (especially with areas that are frequently loaded and unloaded).

#20 CoolisTheName007

  • Members
  • 304 posts

Posted 09 December 2012 - 07:41 AM

Saving the Lua state seems extremely hard and resource intensive. But what do I know, besides an extremely short web search?
If instead one saved part of the state, e.g. the turtle.native queue, or in general peripheral's requests queue's, one would guarantee that peripheral calls would be executed. Then again I'm theorizing on incomplete information about how CC works internally. Just my two bits.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users