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

turtle inventory management

Started by lllScorpionlll, 09 March 2013 - 06:35 AM
lllScorpionlll #1
Posted 09 March 2013 - 07:35 AM
Hello all,

I am newbee in english, so first I am sorry for my bad english I hope you understand me :)/>

The problem is:
I need to count all items in my turtle but this code dont work for me. I try and try it make diferent but it was same result…


for m = 1,16 do
num = 0
num = num + turtle.getItemCount(m)
if num > 384 then
  print "too many items in inventory!"
end
end

Thank for any help!
Cranium #2
Posted 09 March 2013 - 07:38 AM
Split to new topic. Generic title used as none was given.
Lyqyd #3
Posted 09 March 2013 - 07:39 AM
Went to go split this, but got ninja'd.

Put `local num = 0` before the for statement and remove `num = 0` from after it. Your code keeps resetting the counter each time it looped.
lllScorpionlll #4
Posted 09 March 2013 - 07:49 AM
Thanks it works :)/>
ChunLing #5
Posted 09 March 2013 - 08:10 AM
Hmm…are you sure you wouldn't rather be using turtle.getItemSpace() to figure out whether you were running out of space?
lllScorpionlll #6
Posted 09 March 2013 - 08:26 AM
ChunLing thanks for help but no…
So I have the problem again. I used this code in my core code:



term.clear()

for l = 1,16 do
turtle.select(l)
turtle.refuel(64)
end


local num = 0 <- defined num
if turtle.getFuelLevel() == 0 then
term.setCursorPos (1,1)
print "Turtlicka nema palivo! Vloz uhlie do"
print "inventara turtlicky !"
return
end


function begin()
if turtle.getFuelLevel() > 1 then
  term.setCursorPos (1,1)
  print "Sirka kopania:"
  term.setCursorPos (16,1)
  pocetx = tonumber(read())
  if pocetx > 21 then
   term.clear()
   term.setCursorPos (1,1)
   print "Sirka kopania:	"
   term.setCursorPos (1,2)
   print "Povolene cislo je od 1 do 20"
   begin()
  elseif pocetx < 1 then
   term.clear()
   term.setCursorPos (1,1)
   print "Sirka kopania:"
   term.setCursorPos (1,2)
   print "Povolene cislo je od 1 do 20"
   begin()
  end
   function begin2()
   term.setCursorPos (1,1)
   print "Dlzka kopania:	"
   term.setCursorPos (16,1)
   pocety = tonumber(read())
   if pocety > 41 then
	term.clear()
	term.setCursorPos (1,1)
	print "Dlzka kopania:"
	term.setCursorPos (1,2)
	print "Povolene cislo je od 1 do 40"
	begin2()
   elseif pocety < 1 then
	term.clear()
	term.setCursorPos (1,1)
	print "Dlzka kopania:"
	term.setCursorPos (1,2)
	print "Povolene cislo je od 1 do 40"
	begin2()
   end
  end
end
end


begin()
begin2()


function koppravo()
turtle.forward()
turtle.turnRight()
turtle.digUp()
turtle.digDown()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnRight()
turtle.dig()
turtle.forward()
for m = 1,16 do										   <- Here is the code where it was used
  num = num + turtle.getItemCount(m)
  if num > 384 then
   turtle.turnRight()
   turtle.forward()
   turtle.down()
   while true do
	turtle.forward()
	if turtle.detect() == true then
	 for k = 1,16 do
	  turtle.select(k)
	  turtle.drop()
	 end
	 turtle.turnLeft()
	 turtle.turnLeft()
	 return
	end
   end
  end
end
end

function kopvlavo()
turtle.forward()
turtle.turnLeft()
turtle.digUp()
turtle.digDown()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.turnLeft()
turtle.dig()
turtle.forward()
end
function kop()
term.clear()
turtle.forward()
while turtle.detect() == true or turtle.detectUp() == true or turtle.detectDown() == true do
  turtle.digUp()
  turtle.digDown()
  turtle.dig()
end
end

function jadro()
while true do
  turtle.forward()
  if turtle.detect() == true then
   turtle.up()
   for i = 1,7 do
	turtle.dig()
   end
   turtle.forward()
   turtle.digUp()
   turtle.digDown()
   turtle.turnRight()
   for j = 1,pocety do
	for i = 1,pocetx do
	 kop()
	end
	kopvlavo()
	for i = 1,pocetx do
	 kop()
	end
	koppravo()
   end
   turtle.turnRight()
   turtle.forward()
   turtle.down()
   while true do
	turtle.forward()
	if turtle.detect() == true then
	 for k = 1,16 do
	  turtle.select(k)
	  turtle.drop()
	 end
	 turtle.turnLeft()
	 turtle.turnLeft()
	 return
	end
   end
  end
end
end

jadro()

The turtle when it turn right scroll the code:


for m = 1,16 do
  num = num + turtle.getItemCount(m)
  if num > 384 then
   turtle.turnRight()
   turtle.forward()
   turtle.down()
   while true do
    turtle.forward()
    if turtle.detect() == true then
	 for k = 1,16 do
	  turtle.select(k)
	  turtle.drop()
	 end
	 turtle.turnLeft()
	 turtle.turnLeft()
	 return
    end
   end
  end
end

And it not worked :mellow:/>
remiX #7
Posted 09 March 2013 - 08:46 AM
What is the problem … does it give an error or what?
lllScorpionlll #8
Posted 09 March 2013 - 08:49 AM
Easy skip it and nothing to do…

//EDIT Here is image what turtle doing: http://imgupload.sk/...4svagzdnbeq.png
Mining…

FIXED close this topic thanks for all help :)/>