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

simple function - looking for ideas...

Started by gronkdamage, 12 April 2013 - 12:59 PM
gronkdamage #1
Posted 12 April 2013 - 02:59 PM
local function SwitchSlotsIfEmpty()
 if turtle.getItemCount(cs) < 5 then
  cs = cs + 1
  if cs == 4 then
   cs = 1
  end 
 end
end

That's the new version of the function (it's for a mining program I have). Basically; I dig everything in a tunnel - and plug it back up with cobblestone (yeah I know it's slow; but it kills lava - and digs everything for me…) - when running 10 turtles at a time; I can cover a 30 block wide path for mining (going hundreds of blocks deep)… 30 minutes of work has netted me as many as 32 diamonds at one point. :)/>

So my problem is when I run into a LOT of lava; it clearly goes through cobblestone fast - and I ran into a situation (with my first block of code) that it placed the last block of cobblestone, moved to the next spot and dug up a diamond, then tried to put it back (and because of my coding; it keeps trying to place it - thus, it 'locked up' (infinite loop…)

So, I decided to do the block of code above - as you can see it places 59 blocks of cobblestone, and then switches to slot 2. The problem I see, is if it places 177 cobblestone (without digging any (59 x 3)) it's just gonna loop again…

Any suggestions on how to fix this? My brain is fried and I just can't figure a good solution… :(/>
PixelToast #2
Posted 12 April 2013 - 03:03 PM
well, you can check if turtle.place returns true, in wich case you skip to the next slot
gronkdamage #3
Posted 12 April 2013 - 03:24 PM
That turns out to have been my bug; I forgot to check to see if the slot was empty while in the loop. So I've added to check for empty slots.

Do you happen to know what happens if slot 2 is selected, and both slot 1 and 2 have only 5 cobblestone - you mine another piece of cobble. Does it go into the first available slot (slot 1) or the one that's selected (slot 2)? It seems to go into slot 2 (this is for 1.4.7 if it matters; we've decided to play on an FTB server…) - I need to figure out a better way around that if that's the case…

Edit: See, my brain is fried - duh, I can test that and figure it out myself.. :)/>
PixelToast #4
Posted 12 April 2013 - 03:31 PM
im pretty sure it goes to the selected slot, if not it will try to put it in the first available spot