Creating an automated wheat farm, but turtle is only detecting age of first crop

Started by Indie_Rogers, Jun 07, 2021, 11:48 am

Previous topic - Next topic

Indie_Rogers

Before I start, here is the link to the pastebin page for my code.
https://pastebin.com/bGC27L8q
I'm fairly new to LUA, and so i'm sure this is probably some little thing that I just didn't know about.
The first function I found I "found on" (read: stole from) Michael Reeves' twitch stream, where he is making something similar. All it does is select the slot of the desired item (itemName). fuelCheck() I don't end up using anywhere else, since that portion is pretty buggy on it's own.

The main piece is harvest() and harvestrun().
What I want:
  • the turtle will constantly go back and forth, checking which crops are at their maximum age of 7, then mine and re-plant them, while ignoring crops that aren't quite mature yet,
  • when it reaches a block at the end, it will go back to the beginning and start over.

What's happening:
  • if the turtle detects that the first crop is mature and ready to be harvested, the turtle will harvest all of them, even if some of them aren't mature yet, and vice-versa, if the first crop isn't mature, it won't harvest any of them.
  • the turtle keeps turning left and right once it reaches the end, instead of going back.

Lupus590

Your growCheck function doesn't actually look at the crop below the turtle at the time it is called. It uses a global value instead which I believe is 'pointing' to the first crop and so makes the turtle think that everything is full-grown if the first one was. this will also mean that it will think that nothing is if the first wasn't.

Indie_Rogers

Quote from: Lupus590 on Jun 08, 2021, 02:05 amYour growCheck function doesn't actually look at the crop below the turtle at the time it is called. It uses a global value instead which I believe is 'pointing' to the first crop and so makes the turtle think that everything is full-grown if the first one was. this will also mean that it will think that nothing is if the first wasn't.
Ohhhhh! I see, so I need to make it a local variable otherwise it won't get updated every time the function is called! That's different from Python, my main language, but kind of makes sense too.

update: just tried it and it fixed my issue.