95 posts
Location
A CPU some where in Bolton, UK
Posted 03 February 2016 - 04:18 PM
Hi all,
I am writing my own mining program for a turtle but i dont want it to mine certain blocks, i have stored the names in a table
local DNMineTbl = {"minecraft:stone" = true, "minecraft:dirt" = true}
is the table correct? and also when im checking the walls, is there a way i can check what 1 block is then check to see if its in the table at all?
I know i can use turtle.inspect() but once it has done that how would i be able to compair it to the table?
Edited on 04 February 2016 - 12:25 AM
570 posts
Posted 03 February 2016 - 04:54 PM
First off, you need to surround all table keys with square brackets unless it's a string without special characters (in which case you don't need the quotes either):
local DNMineTbl = {
["minecraft:stone"] = true,
["minecraft:dirt"] = true
}
Now, to check if a block should not be mined, you would index the table with the block ID. If it's true, do not mine.
local ok, inspectionData = turtle.inspect()
if ok then --# ok will be false if the block is air.
if not DNMineTbl[inspectionData.name] then --# if the table does not contain the block, or has it set to false, mine it.
--# mine the block
end
end
I recommend you take a look at
this page of the PIL.
95 posts
Location
A CPU some where in Bolton, UK
Posted 03 February 2016 - 05:17 PM
First off, you need to surround all table keys with square brackets unless it's a string without special characters (in which case you don't need the quotes either):
local DNMineTbl = {
["minecraft:stone"] = true,
["minecraft:dirt"] = true
}
Now, to check if a block should not be mined, you would index the table with the block ID. If it's true, do not mine.
local ok, inspectionData = turtle.inspect()
if ok then --# ok will be false if the block is air.
if not DNMineTbl[inspectionData.name] then --# if the table does not contain the block, or has it set to false, mine it.
--# mine the block
end
end
I recommend you take a look at
this page of the PIL.
Thank you!
95 posts
Location
A CPU some where in Bolton, UK
Posted 04 February 2016 - 12:18 AM
Ok, seams the program is semi working but cant figure out where its going wrong…
Basiclly the turtle isn mining anything, but if i change the stone BlockID to false in the table it mines everything also when it reaches bedrock it just spins round.
Can someone just double check the code for me?
moved = 0
local DNMineTbl = {
["minecraft:stone"] = true,
["minecraft:dirt"] = true
}
local function fuelCheck()
susFuel = false
while susFuel == false do
if turtle.getFuelLevel() <= 140 then
turtle.select(16)
turtle.refuel(1)
else
susFuel = true
end
end
end
local function checkWalls()
bedrockNotDetetcted = true
while bedrockNotDetetcted == true do
local block, insepctionData = turtle.inspect()
for t=1,4 do
if block then
if not DNMineTbl[insepctionData.name] then
turtle.dig()
turtle.turnLeft()
else
turtle.turnLeft()
end
else
turtle.turnLeft()
end
end
bedrockCheck = turtle.inspectDown()
if bedrockCheck ~= "minecraft:bedrock" then
turtle.digDown()
moved = moved + 1
turtle.down()
else
bedrockNotDetetcted = false
endPos()
end
end
end
local function endPos()
fuelCheck()
for u=1, moved do
turtle.up()
end
end
local function startPos()
turtle.digDown()
turtle.down()
moved = moved + 1
turtle.digDown()
turtle.down()
moved = moved + 1
turtle.select(14)
turtle.placeUp()
turtle.select(1)
checkWalls()
end
fuelCheck()
startPos()
Edited on 03 February 2016 - 11:21 PM
7083 posts
Location
Tasmania (AU)
Posted 04 February 2016 - 12:41 AM
if not DNMineTbl[insepctionData.name] then
turtle.dig()
This code digs if the found block isn't in the "do not mine" table. Since stone is in that table, and most of the underground consists of stone, the turtle won't be able to progress very far - it's not allowed to clear a path through the stuff!
bedrockCheck = turtle.inspectDown()
if bedrockCheck ~= "minecraft:bedrock" then
Take another look at the example Lignum gave you for turtle.inspect(); it also applies to
turtle.inspectDown(). Here you've got things setup so that "bedrockCheck" will only ever be true or false, never a string.
121 posts
Posted 04 February 2016 - 12:53 AM
Bomb bloke,
Beet me to it.
You might also want to look at how you are defining your functions and the order that they are in. :)/>
95 posts
Location
A CPU some where in Bolton, UK
Posted 04 February 2016 - 12:59 AM
if not DNMineTbl[insepctionData.name] then
turtle.dig()
This code digs if the found block isn't in the "do not mine" table. Since stone is in that table, and most of the underground consists of stone, the turtle won't be able to progress very far - it's not allowed to clear a path through the stuff!
bedrockCheck = turtle.inspectDown()
if bedrockCheck ~= "minecraft:bedrock" then
Take another look at the example Lignum gave you for turtle.inspect(); it also applies to
turtle.inspectDown(). Here you've got things setup so that "bedrockCheck" will only ever be true or false, never a string.
The DNMineTbl is only for the walls, the turtle digs down regardless of the block under it hence the bedrockCheck, i have changed added what Lignum said to the inspectDown() but still the program isnt working correct, if it detects 1 things that isnt on the Table then it will mine all 4 walls regardless to whats on it
Bomb bloke,
Beet me to it.
You might also want to look at how you are defining your functions and the order that they are in. :)/>
shouldnt matter what order the functions are in becouse the functions are all read then called.
EDIT: my bad, the endPos works now that i moved it above checkWalls(), never had that happen to me before :P/>
Edited on 04 February 2016 - 12:04 AM
121 posts
Posted 04 February 2016 - 01:10 AM
For the thing where it is not digging the correct block try moving the inspect into the for loop so every time it rotates it re-inspects it. :)/>
95 posts
Location
A CPU some where in Bolton, UK
Posted 04 February 2016 - 01:15 AM
For the thing where it is not digging the correct block try moving the inspect into the for loop so every time it rotates it re-inspects it. :)/>
HAHAHA thank you, never thought of that!
Program is 100% fixed, thanks for the help everyone!