This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lettuce's profile picture

[Question][Lua][1.4] How do I specify a turtle's "drop zone?"

Started by Lettuce, 14 August 2012 - 07:46 PM
Lettuce #1
Posted 14 August 2012 - 09:46 PM
I am writing a series of mining programs in CC 1.4, and I want to take advantage of the new chest storage system. I'll try to explain as best I can, as my code is not yet written.
I want this to work similar to the excavation demo, although it will already (presumably) be underground. Triangulation with GPS is not feasible, as it will be underground, and probably quite large. How do I record a turtle's starting location, and, if possible, previous location so it can return straight to mining?

Thank you,
Lettuce
OmegaVest #2
Posted 14 August 2012 - 09:49 PM
Aside from a numerical tracker that updates a separate file every time it moves, there's not really any way to do so aside from GPS.

If he has the code posted, go look at Cookiebal's programs for Project World Eater. It's very similar to what you are looking to do, I believe.


Also, check out the Magic Turtle API.
Lettuce #3
Posted 14 August 2012 - 10:10 PM
I think "coord" is what I'm looking for, but I don't know how to set them. I would rather not download an API, as I intend to submit this program to the community, and not everyone has Magic Turtle. Also, I could not find Cookiebal's code.
OmegaVest #4
Posted 14 August 2012 - 10:21 PM
Easiest way to set them is to set up a disk drive, put a computer on top. Edit a startup file on the disk that does nothing but write (or transfer) a file with the coordinates of the turtle, and only place the turtles beside this one. It is not a perfect system, but it works.

So long as you know what direction the disk drive is facing, you can make a set of functions that turn and move the turtle, and update their coordinates as it does (both file and variable versions should be updated if you plan on abruptly stopping the turtle, like logoffs and whatnot, otherwise, just make an autosave counter; every few moves, it puts the coordinates and direction to the file).
D3matt #5
Posted 14 August 2012 - 10:59 PM
Nah, you don't need a disk drive. I think the best way is to just assume the turtle starts at 0,0 in front of the chest. Have it go mining normally, but use your own move functions that increment a counter every time it moves (and add a check and loop to make sure it does actually move). If you want to be extra sure you can write the counter to a file on the hard drive. I have a function similar to this written out but it's on my laptop.
Lettuce #6
Posted 15 August 2012 - 12:04 AM
D3Matt,
Do you have a sample script? I'm unsure what you mean. How do I implement such a counter? I have a looping moveForward() function already, editing that for this purpose probably won't be difficult, if I knew what variables to use.
Lyqyd #7
Posted 15 August 2012 - 12:58 AM
You might be interested in taking a look at my location API. I'd encourage you to use it, but if you're really stuck on wanting to reinvent the wheel, you could perhaps draw some inspiration from it for your own location-tracking system.
Pharap #8
Posted 15 August 2012 - 01:23 AM
I am writing a series of mining programs in CC 1.4, and I want to take advantage of the new chest storage system. I'll try to explain as best I can, as my code is not yet written.
I want this to work similar to the excavation demo, although it will already (presumably) be underground. Triangulation with GPS is not feasible, as it will be underground, and probably quite large. How do I record a turtle's starting location, and, if possible, previous location so it can return straight to mining?

Thank you,
Lettuce

Why don't you just have an x, y and z variable?
Everytime the turtle moves a certain direction, change one of the variables. If you need other turtles to know, just broadcast it over rednet.
No need to log it to a file or anything, just make sure you set it when the turtle starts up so it can add and subtract as it moves.
If you want to you can log it, but unless you change program or reboot the turtle, the variables will be there for access. Maybe have the turtle tell a computer it's position before changing program so you can use the distance feature of rednet to check if it's moved since then, and instruct it to set new co-ordinates.
Lettuce #9
Posted 15 August 2012 - 01:24 AM
Lyqyd, I'm not trying to sound stubborn, but for the program I have in mind, (a mining program, with x, y, and z dimensions) new API's and GPS is not feasible, as I can't expect people who want to use this program (I want to submit it on these forums) to have that API or the patience to set up GPS hosts. I suppose I must reinvent the wheel.

I have an idea though. If I set up an uncommon block to find underground, such as stone brick, or any other object the player chooses, the turtle could place it and look for it on its return, eliminating hours of coding and testing twenty variables.
Lyqyd #10
Posted 15 August 2012 - 01:33 AM
Lyqyd, I'm not trying to sound stubborn, but for the program I have in mind, (a mining program, with x, y, and z dimensions) new API's and GPS is not feasible, as I can't expect people who want to use this program (I want to submit it on these forums) to have that API or the patience to set up GPS hosts. I suppose I must reinvent the wheel.

I have an idea though. If I set up an uncommon block to find underground, such as stone brick, or any other object the player chooses, the turtle could place it and look for it on its return, eliminating hours of coding and testing twenty variables.

That actually sounds a great deal more complex than simply keeping track of the location. And stubborn isn't a bad thing, I just think you're setting yourself up for more work than you need to. Honestly, I think that saying that your program requires a small API wouldn't be too much work for the users in this community. Besides, the more programs that use a given API, the more likely it is that people will already have it installed! Anyway, if you do decide to go with the location-tracking method (which I think would be easier than trying to pathfind for a certain block type), it may help to take a look at what's already been done just for some ideas.

As always, we are here to help!
Lettuce #11
Posted 15 August 2012 - 01:38 AM
I am writing a series of mining programs in CC 1.4, and I want to take advantage of the new chest storage system. I'll try to explain as best I can, as my code is not yet written.
I want this to work similar to the excavation demo, although it will already (presumably) be underground. Triangulation with GPS is not feasible, as it will be underground, and probably quite large. How do I record a turtle's starting location, and, if possible, previous location so it can return straight to mining?

Thank you,
Lettuce

Why don't you just have an x, y and z variable?
Everytime the turtle moves a certain direction, change one of the variables. If you need other turtles to know, just broadcast it over rednet.
No need to log it to a file or anything, just make sure you set it when the turtle starts up so it can add and subtract as it moves.
If you want to you can log it, but unless you change program or reboot the turtle, the variables will be there for access. Maybe have the turtle tell a computer it's position before changing program so you can use the distance feature of rednet to check if it's moved since then, and instruct it to set new co-ordinates.

That gave me an idea! I was about to ask about how to track x, but all I need to know is if x = 0, if it's negative, turnRight, if positive, left. I need to stop going to Ask a Pro, I'm embarassing myself. Last time I forgot some parenthesis. I'll submit this when I get it done.
Pharap #12
Posted 15 August 2012 - 01:41 AM
I am writing a series of mining programs in CC 1.4, and I want to take advantage of the new chest storage system. I'll try to explain as best I can, as my code is not yet written.
I want this to work similar to the excavation demo, although it will already (presumably) be underground. Triangulation with GPS is not feasible, as it will be underground, and probably quite large. How do I record a turtle's starting location, and, if possible, previous location so it can return straight to mining?

Thank you,
Lettuce

Why don't you just have an x, y and z variable?
Everytime the turtle moves a certain direction, change one of the variables. If you need other turtles to know, just broadcast it over rednet.
No need to log it to a file or anything, just make sure you set it when the turtle starts up so it can add and subtract as it moves.
If you want to you can log it, but unless you change program or reboot the turtle, the variables will be there for access. Maybe have the turtle tell a computer it's position before changing program so you can use the distance feature of rednet to check if it's moved since then, and instruct it to set new co-ordinates.

That gave me an idea! I was about to ask about how to track x, but all I need to know is if x = 0, if it's negative, turnRight, if positive, left. I need to stop going to Ask a Pro, I'm embarassing myself. Last time I forgot some parenthesis. I'll submit this when I get it done.

More importantly, read all the posts lol.
Lettuce #13
Posted 15 August 2012 - 02:00 AM
Pharap, several of these posts came while I was writing responses.
Pharap #14
Posted 15 August 2012 - 02:05 AM
Pharap, several of these posts came while I was writing responses.
I don't doubt they did.