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

Help with "descent" function and injection into default Excavate script

Started by Zafoquat, 11 August 2015 - 04:20 PM
Zafoquat #1
Posted 11 August 2015 - 06:20 PM
TL:DR: I want to add a function that dives the turtle down until it hits a non-air non-water block to the default excavate script. This would allow my turtle to skip the large sections of air and water between starting location and surface level. If you are curious I have a sky base over a deep ocean.

Part 1:

I may be tackling this in entirely the wrong direction, if so please feel free to redirect my pursuits at even the most fundamental levels.

I am going about it with the turtle.detectDown() command.

turtle.detectDown() reports back a false for air blocks and water blocks and true for solid blocks

I guess i'm having trrouble writing my while loops to accomdate the false report.

"while turtle.detectDown(1) do" does not seem to trigger with a false report like "while turtle.detectDown() do" does with a true report

The test I setup was

local function rushDown()
while turtle.detectDown(1) do
turtle.down()
end
while turtle.detectDown() do
write.term("Reached Bottom")
end
end


But my issues with turning a false report from detectDown into a do function in a while loop is really stalling me.





Part 2

I would then like to inject it into the excavate script.. I don't know a good way to get it dumped into pastebin or this forum to do an in-line reference. I copied the Excavate script to the root directory to edit it. I'm hoping that for the purpose of the second part of this question that you, as the viewer and possibly answerer, would have access to this script independently for review and reference. Apologies ahead of time.

It appears to start mining with use of the "Return to Mining" function triggered by a change of local variables in the "Restocking" function. It does not seem ot have a true "start mining" section and simply starts its loop with checking for full inventory or low fuel, returning to base, restocking, and returning to mining. When the loop is unstated those coordinate variables are set to ~ ~ ~, changed dynamically by progression of the loop, which allows use of the "Return to Mining" section to start the first mined block.

so its got a "local xPos,zPos = 0,0" and "local xDir,zDir = 0,1" setup initially

the function returnSupplies() sets "local x,y,z,xd,zd = xPos,depth,zPos,xD with a goto( 0,0,0,0,-1)

there is no true "Resuming mining" function, just a print( function with a goto( x,y,z,xd,zd) call from the previously set variables in the "returnSupplies" function

So if I get my rushDown function functional I should be able to have it set the local variables for x,y,z,xd,zd based on the xPos,depth,zPos, and xD variables and do the goTo( 0,0,0,0,-1) just as the returnSupplies function does it (removing those steps from the returnSupplies function)

I think it would be safe to inject the rushDown function directly above the print( "Resuming mining…") and goTo( x,y,z,xd,zd) commands



Again, if I am doing this the wrong way, or there is an existing user-created excavation script you would recommend adapting with my rushDown function for better results, please don't hesitate to make any and all recommendations.

Thanks in advanced
-Chris
KingofGamesYami #2
Posted 11 August 2015 - 09:22 PM
You should be able to simply go down until you can't go down anymore - like this:


while turtle.down() do end

Also, turtle.detectDown doesn't take an argument, it'll ignore whatever you give it.

As for the excavate script, I'd think it easier to create your own script entirely, perhaps with some functions copied from that program. There probably isn't a user-created script to do what you want, but there are several mining scripts you may be able to take ideas from or modify to fit your purposes. Those can be found in the 'turtle' subforum, which is located within the 'programs' subforum.
Bomb Bloke #3
Posted 11 August 2015 - 11:25 PM
The "simple" solution would be to just do this:

while turtle.down() do end
turtle.select(1)  -- Have a diamond chest there or something.
turtle.dig()
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
shell.run("excavate whatever")

Yeah, the mining chest'll be underwater somewhere, but I imagine you're capable of going down to get it.
Zafoquat #4
Posted 11 August 2015 - 11:40 PM
thank you for your quick response

the
while turtle.down() do end
part works exactly as I wanted and avoids a where loop

I have not looked around too much at the coding behind some of the user submissions, but I will shortly, time allowing.

I would like to get this turtle kicked off by modifying an existing script, to better familiarize myself with the constituent functions pulled together to make these work without all the many hiccups that can happen (from falling blocks, to properly dropping off at a chest, to properly refueling, to properly determining bedrock, to properly avoiding/dispatching mobs, etc etc etc.


i'd really like to start working on one from scratch just to encounter and work on these bugs I'm sure i'd develop as a good LUA learning experience. I would like to get a basic working setup going first though


the mature scripts work on a table of variables that are dyamicly updated by the functions…


This is where I'm messing up the current excavate script.. placing the
 while turtle.down() do end
at the start of the script after it declares its base variable settings drops the turtle down before mining but sets the "return" position to that dropped down level, expecting a chest at that location..

I feel like I'm missing something right in front of me and simple.. but I can't figure out how to keep the starting position correct and doing a 50+ block drop before mining…

do i need to manually set those variables for x and z positions and directions and depth?

The "simple" solution would be to just do this:

while turtle.down() do end
turtle.select(1)  -- Have a diamond chest there or something.
turtle.dig()
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
shell.run("excavate whatever")

Yeah, the mining chest'll be underwater somewhere, but I imagine you're capable of going down to get it.


yeah, no item transportation in my mod pack, so chest location is a big factor for me, moving double chests off the ocean floor and a 60 blocks of air defeats the adaption

i like your solution to deposit a new chest at that new location though, its an effective workaround in most cases