ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: Indie_Rogers on Jun 07, 2021, 11:48 AM

Title: Creating an automated wheat farm, but turtle is only detecting age of first crop
Post by: Indie_Rogers on Jun 07, 2021, 11:48 AM
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:

What's happening:
Title: Creating an automated wheat farm, but turtle is only detecting age of first crop
Post by: Lupus590 on Jun 08, 2021, 02:05 AM
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.
Title: Creating an automated wheat farm, but turtle is only detecting age of first crop
Post by: Indie_Rogers on Jun 08, 2021, 03:09 PM
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.