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

Comparing Inventory Question - Basic

Started by guamie, 20 August 2013 - 04:06 PM
guamie #1
Posted 20 August 2013 - 06:06 PM
Hey guys,

Thanks for the help in advance.

So, I've had a program that just places and then breaks a stack of gravel at a time… but now my dreams of world domination have circled back and now I'd like it to be able to process 15 stacks! Shockingly daring I know.

Here's my code as it stands.


--Gravel to Flint

--slotCount() Counter
sCount = 1
turtle.select(sCount)
--Changes Inventory slot when slot is empty
function slotCount()
while turtle.getItemCount(sCount) < 1 do
  sCount = (sCount%15)+1
end   
end

print("Making Gravel into Flint.  Uses inventory slot 1-15.")
print("Press Control + T to stop.")

sleep(.5)
print("3")
sleep(.5)
print("2")
sleep(.5)
print("1")
sleep(.5)
print("Starting...")
while true do
turtle.place()
  if turtle.detect() then
   turtle.dig()
else
print("Gravel Supply Expended")
break
  end
end


The problem is, that when the first stack finishes, it places the 64th flint in inv slot #1, this is fine, but then of course it craps out like it is supposed to. So what I'd like it to do… (and this is also because I'd like to understand how to compare items in an inventory in this specific way for another program I'd like to work on)… is have the turtle have a function that compares it's current slot (sCount) to slot 16 (hardcoded is fine, I can make it a variable afterwards once I'm sure I understand)

I know my programming is bad and I should feel bad, but thanks for reading!
guamie #2
Posted 20 August 2013 - 08:31 PM
ok Well, now I am here….



--Gravel to Flint

--slotCount() Counter
sCount = 1
flintCompare = 16
turtle.select(sCount)
--Changes Inventory slot when slot is empty
function slotCount()
while turtle.getItemCount(sCount) < 1 do
  sCount = (sCount%15)+1
end   
end
function blarg()
turtle.place()
if turtle.detect() then
  turtle.dig()
else
  print("End")
end
end

print("Making Gravel into Flint.  Uses inventory slot 1-15.")
print("Press Control + T to stop.")

sleep(.5)
print("3")
sleep(.5)
print("2")
sleep(.5)
print("1")
sleep(.5)
print("Starting...")
while true do
slotCount()
if turtle.compareTo(16) then
  sCount = sCount + 1

else
  blarg()

end

end


but after first stack i get the error <filename>:12: Slot number 17 out of range
Last1Here #3
Posted 20 August 2013 - 09:30 PM
This should work:


local slot = 1
turtle.select(1)

function checkSlot()
  if turtle.getItemCount(slot) == 0 then
	slot = slot + 1
	turtle.select(slot)
  elseif turtle.compareTo(16) == true then
	slot = slot + 1
	turtle.select(slot)
  end
end

function dig()
  turtle.place()
  turtle.dig()
  sleep(0.5)
end

print("Gravel in 1-15, 1 piece of flint in 16.")
print("Press Enter to continue:")
read()

repeat
  dig()
  checkSlot()
until slot == 16

print("Finished")
Edited on 20 August 2013 - 07:32 PM
guamie #4
Posted 20 August 2013 - 10:37 PM
Thanks!

I also got it to work using this:



--Gravel to Flint

--slotCount() Counter
sCount = 1
flintCompare = 16
turtle.select(sCount)
digCount = 0
function blarg()
turtle.place()
if turtle.detect() then
  turtle.dig()
  digCount = digCount + 1
  term.clear()
  print("Repititions: "..digCount)
else
  print("End")
end
end

print("Making Gravel into Flint.  Uses inventory slot 1-15.")
print("Press Control + T to stop.")

sleep(.5)
print("3")
sleep(.5)
print("2")
sleep(.5)
print("1")
sleep(.5)
print("Starting...")
while true do
if turtle.compareTo(16) and sCount < 16 then
  sCount = sCount + 1
  turtle.select(sCount)
elseif not turtle.compareTo(16) then
  blarg()
end

if turtle.compareTo(16) and sCount == 16 then
  break
end


end

But I also like to see how you've done it, it lets me get a better idea of how other people do things :D/>
albrat #5
Posted 21 August 2013 - 08:24 PM
I know this is probably a silly comment… But if you have IC2 machines there is an easier way to produce flint, If you use a macerator with gravel it gives flint. :)/>
Last1Here #6
Posted 21 August 2013 - 09:48 PM
I know this is probably a silly comment… But if you have IC2 machines there is an easier way to produce flint, If you use a macerator with gravel it gives flint. :)/>

A valid point, why would he ever need vast amount of flint anyway :D/>
guamie #7
Posted 22 August 2013 - 11:57 PM
its more for the practice to be honest, i play on ftb 1.4.7 and know all about ic2…. just nothing about programming.


also

flint for industrial tnt i suppose?

best answer i could come up with for ever actually needing flint……