First: Sorry for my bad english :rolleyes:/>/>
Im currently trying to code an 'Automated Nuclear Reactor Control' Programm with a Computer and a Wireless Turtle beside the Reactor Champ… It works already very good - the Computer has a OpenCCsensor with a 'Inventory Sensor Card', scanning the Items every Second and compares them with a hardcoded Table.. If an Item is missed the Computer tells the Turtle to place a new of which Item into the Rector, and the Turtle have's 2 different Chests with á Uran or Coolant Cells… This part works perfect.
But my Problem is now, that the Turtle also needs to replace "Depleted Uran" Cells - and heres my @topic Question:
Is it possible to tell the Turtle to select a specified Slot of another (not himselfs) Inventory?
I only know 'turtle.select()' but that is only for the Turtle-Inventory, not for an extern-Inventory :unsure:/>/>
The Computer knows the Slot-Number.. I also have a function on the Turtle for 'chestobj.getSizeInventory()' … But all this is currently useless coz i dont know how to tell the turtle "suck slot#21 of Reactor-Inventory" :(/>/>
Is there maybe some trick? Or do i need to take all Item out and apply turtle.getItemDetail() on it? :wacko:/>/>
//EDIT: maybe helpful my Code:
Spoiler
--[[
.. Turtle file for Reactor-Control .. by meigrafd
--]]
---[[ CONFIG - START ]]
-- Modem channel to listen for commands from Computer.
local ModemChannel = 32768 -- Broadcast channel.
-- Maximum loop time (default: 0.5s)
local loopT=0.5
-- Chest Inventory Sides for which Items. Only valid sides: left, right, back, up
-- NOTE: Fastest for Coolant will be "up"
-- (wireless modem is always on the left, but no problem)
-- put a chest below the turtle as trash where it drops all it takes outa reactor
chestCoolant = "up"
chestUran = "back"
chestTrash = "down"
chestReactor = "front" --turtle must be placed so this fits!
---[[ CONFIG - END ]]
---[[ functions ]]
function getDeviceSide(deviceType)
-- loop through all the sides
for i,side in pairs(rs.getSides()) do
if (peripheral.isPresent(side)) then
-- Yup, there is something on this side
if (peripheral.getType(side) == string.lower(deviceType)) then
-- Yes, this is the device type we need, so return the side
return side;
end
end
end
--nothing found, return nil
return nil;
end
function changeReactorState(state)
print("Changing Reactor State to: "..state)
if state == "off" then
rs.setOutput(chestReactor, false)
else
rs.setOutput(chestReactor, true)
end
end
function turn(side)
if side == "left" then
turtle.turnLeft()
elseif side == "right" then
turtle.turnRight()
elseif side == "front" then
turtle.turnRight()
turtle.turnRight()
elseif side == "back" then
turtle.turnLeft()
turtle.turnLeft()
end
end
-- verify reactor in front
function verifyReactor()
local success, detect = turtle.inspect()
if string.find(string.lower(detect.name), "reactor") then
return true
else
return false
end
end
function Coolant()
if chestCoolant == "up" then
if not turtle.suckUp(1) then
print("WARNING: can't pick up the item!")
changeReactorState('off')
end
elseif chestCoolant == "down" then
if not turtle.suckDown(1) then
print("WARNING: can't pick up the item!")
changeReactorState('off')
end
else
turn(chestCoolant)
if not turtle.suck(1) then
print("WARNING: can't pick up the item!")
changeReactorState('off')
end
turn(chestReactor)
end
-- verify reactor in front
while verifyReactor() == false do
turn('left')
end
success = turtle.drop()
commandsexecdCount = commandsexecdCount + 1
end
function Uran()
if chestUran == "up" then
if not turtle.suckUp(1) then
print("WARNING: can't pick up the item!")
changeReactorState('off')
end
elseif chestUran == "down" then
if not turtle.suckDown(1) then
print("WARNING: can't pick up the item!")
changeReactorState('off')
end
else
turn(chestUran)
if not turtle.suck(1) then
print("WARNING: can't pick up the item!")
changeReactorState('off')
end
turn(chestReactor)
end
-- verify reactor in front
while verifyReactor() == false do
turn('left')
end
success = turtle.drop()
commandsexecdCount = commandsexecdCount + 1
end
--[[ Internal values ]]
local version = 0.2
turtle.select(1)
commandsexecdCount=0
w,h = term.getSize()
sleep(2) -- wait for 2s
--[[ Main program ]]
term.clear()
-- detect Modem
print('Connecting to modem...')
sleep(0.5)
side = getDeviceSide("modem")
if side == nil then
error('Error: Could not connect to Modem!')
else
myModem = peripheral.wrap(side)
myModem.open(ModemChannel)
if myModem.isWireless() then
print('success (wireless)')
else
print('success')
end
sleep(0.5)
end
sleep(3)
term.clear()
--changeReactorState('on')
-- Receive messages Event loop
while true do
tID = os.startTimer(loopT) -- Wait for loopT secounds.
repeat
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent()
if event == "modem_message" then
local Slot = message.slot
local Item = message.item
print('('..commandsexecdCount..') slot#'..Slot..' -> '..Item)
if string.find(string.lower(Item), "coolant") then
Coolant()
elseif string.find(string.lower(Item), "uran") then
Uran()
else
print('ERROR: received unknown Item "'..Item..'"')
end
end
-- exit repeat loop on timer event
until (event == "timer" and modemSide == tID)
end