My code gives an "attempt to call a nil value" on the computer controlled seed analyzer in Minecraft

1.3k Views Asked by At

So I have spent a few hours looking for documentation on the item "Computer Controlled Seed Analyzer" with no current information that is useful. My goal is to set up a seed analyzer that will check for a plant next to the analyzer and analyze it.

My code:

 local sides = require("sides")

 if hasPlant(sides.left) and isAnalyzed() == false then
     analyze(side.left)
 end

From my logic, I believe the outcome should analyze the seed, but instead it gives an attempt to call a nil value (global hasPlant). From my research, sides were not defined at the time therefor I added the local line. What else would I be missing?

The Computer Controlled Seed Analyzer

1

There are 1 best solutions below

0
On

Two problems here:

  1. The mods involved are currently buggy, so OpenComputers integration doesn't work at all. I opened pull request #1260 for AgriCraft and #31 for InfinityLib that will fix it. Until it's fixed, there's nothing you can do in-game to make it work. If you don't want to wait for official releases with the fixes, you can use my unofficial builds of AgriCraft and of InfinityLib, which I used to test my PRs and the below code.
  2. The Lua code you're writing is wrong. I'm not sure where you got it from, but here's how you make it work:
if component.agricraft_peripheral.hasPlant("EAST") and component.agricraft_peripheral.isAnalyzed() == false then
    component.agricraft_peripheral.analyze("EAST")
end

Of note:

  • The Agricraft API takes the strings DOWN, UP, NORTH, SOUTH, WEST, and EAST, rather than the numeric constants from side.
  • The functions provided by components in OpenComputers aren't globals; they're nested inside of component.
  • You may need local component = require("component"), so add it to the top if you get an error about it missing. (It works for me without it, but a bunch of documentation says you need it.)