Jump to content




[Lua] Crafty Turtle Issue with Wheat


  • You cannot reply to this topic
10 replies to this topic

#1 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 17 December 2012 - 11:28 AM

Having a problem with a farming turtle script. It's supposed to go through and get a row of wheat and melons in a zig-zag fashion, then dig up a row of melons at the end of the field.

That part works perfectly. However, near the end, I wanted to automatically craft bread and throw it in the chest before it, but it's not really working out very nicely.

Here's the part of the script that controls bread crafting:
local total = 0
for i=1, 16 do
  total = total + turtle.getItemCount(i)
end

for i=1, 16 do
  if turtle.getItemCount(i) > 0 then
    turtle.select(i)
    repeat until not turtle.dropDown(1)
  end
end

for slot=1, 3 do
  turtle.select(slot)
  for w=1, math.ceil(total/3) do
    if not turtle.suckDown() then
      break
    end
  end
end

turtle.craft(turtle.getItemCount(1))

My logic with this was to throw out anything that isn't wheat (in slot 1) in the chest in front, then count all of the remaining items, which all should be wheat. Then it drops all of the items down, 1 by 1. After that, it sucks up a third of the dropped items into slots 1, 2, and 3, then crafts it at the end.

The full code:
Spoiler

At the end, it only drops everything on the ground. That or just throws all the wheat in the chest, uncrafted. What am I doing wrong here?

#2 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 11:34 AM

In the second for loop in the auto-bread crafting you have "repeat until not turtle.dropDown(1)" but what is it repeating? O.o

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 17 December 2012 - 11:37 AM

It just repeats nothing until it can't drop anything anymore. I use it all the time.

#4 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 17 December 2012 - 04:26 PM

for i=1, 16 do
  if turtle.getItemCount(i) > 0 then
    turtle.select(i)
    repeat until not turtle.dropDown(1)
  end
end

right there you are telling it to go through all 16 slots, if they have items toss them out, you do not check if it is wheat first, you should have wheat in the first slot always and then use the code

turtle.select(1)
for i=2,16 do
  if turtle.getItemCount(i)>0 and not turtle.compareTo(i) then
    turtle.select(i)
    turtle.dropDown(turtle.getItemCount(i))
    turtle.select(1)
  end
end


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 17 December 2012 - 07:55 PM

Use turtle.transferTo as well, it'll make this sort of thing far simpler.

#6 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 18 December 2012 - 02:05 AM

View PostLyqyd, on 17 December 2012 - 07:55 PM, said:

Use turtle.transferTo as well, it'll make this sort of thing far simpler.
Probably should've mentioned that I'm in FTB.

View PostKaoS, on 17 December 2012 - 04:26 PM, said:

for i=1, 16 do
  if turtle.getItemCount(i) > 0 then
    turtle.select(i)
    repeat until not turtle.dropDown(1)
  end
end

right there you are telling it to go through all 16 slots, if they have items toss them out, you do not check if it is wheat first, you should have wheat in the first slot always and then use the code

turtle.select(1)
for i=2,16 do
  if turtle.getItemCount(i)>0 and not turtle.compareTo(i) then
    turtle.select(i)
    turtle.dropDown(turtle.getItemCount(i))
    turtle.select(1)
  end
end
This should work. Thanks.

#7 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 18 December 2012 - 02:10 AM

View PostKingdaro, on 18 December 2012 - 02:05 AM, said:

This should work. Thanks.

No problem, good luck


View PostKingdaro, on 18 December 2012 - 02:05 AM, said:

Probably should've mentioned that I'm in FTB.

turtle.transferTo also works in FTB... they update fast

#8 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 18 December 2012 - 02:14 AM

View PostKaoS, on 18 December 2012 - 02:10 AM, said:

View PostKingdaro, on 18 December 2012 - 02:05 AM, said:

Probably should've mentioned that I'm in FTB.

turtle.transferTo also works in FTB... they update fast
tHAT WOULD'VE BEEN HELPFUL TO KNOW

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 18 December 2012 - 02:29 AM

sorry, thought u would have known, since i assumed you used the API page to get info on methods you used.

#10 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 18 December 2012 - 02:50 AM

I always use the wiki, but I always thought transferTo was in a version later than FTB's. :/

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 18 December 2012 - 03:01 AM

View PostKingdaro, on 18 December 2012 - 02:50 AM, said:

I always use the wiki, but I always thought transferTo was in a version later than FTB's. :/

Ahh ok. lol. should have used the "lua" program to test ;)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users