Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0

Detecting robot upgrades


I've been writing an all-purpose farming program and wanted to account for all three possible power sources: the coal generator, solar panel, and just using charger blocks. The generator has an API, so a simple if statement with the component library can check for it; however there is no function to detect certain upgrades such as the solar panel.

Is there a way to tell if one is installed, even at night?

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

computer.getDeviceInfo was created exactly for this purpose: provide information about devices that don't have a component (processors, solar generators, memory banks).

computer.getDeviceInfo returns a table. Its keys are addresses of devices, values that correspond to these keys are tables filled with basic information about a device. So you need to iterate over the returned table and compare fields of tables to expected values.

For the solar generator upgrade, class is "power", and description is "Solar panel". Here's how you can check if the solar panel is installed.

local solarGenDetected = false
for addr, info in pairs(computer.getDeviceInfo()) do
  if info.class == "power" and info.description == "Solar panel" then
    solarGenDetected = true

if solarGenDetected then
  print("solar generator is installed")


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.