Jump to content




Returning an error string if specific peripheral not found


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

#1 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 19 July 2014 - 07:56 AM

I've got a program that automatically detects certain types of peripherals through Openperipheral, and displays things like fluid levels, energy levels, and storage amounts. Right now, it works okay, but I'm trying to detect if a certain type of peripheral isn't connected to the network, and return an error message. It's crashing the program when it doesn't find the fluids normally connected.
I'm not sure it's returning the string properly. I keep getting errors on line 71, index expected, got string.
I'm 90% certain I'm doing it wrong, but if anyone could help me improve it, I would appreciate it.

http://pastebin.com/iyPUG8XC

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 July 2014 - 08:18 AM

You're looping through all connected peripherals. For each connected peripheral, you check if the wrapped variable exists, and if it has certain methods. If so, you add values to the table you declared. If not, you overwrite the table with a string and continue on. You're finding a peripheral that doesn't match what you want and then finding one that does, by which time your table is now a string.

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 19 July 2014 - 03:13 PM

Hmm, yeah, I see your point. How would I implement what I want though? I wanna have it display the "error" string when nothing was found for that type of peipheral.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 19 July 2014 - 03:20 PM

I'd say in your rendering code check to see if storage.capacity is 0 and if it is, then output the string as opposed to the percentage bar or however you wanted to lay out those stats.

#5 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 19 July 2014 - 03:42 PM

I've moved around where I check the info, and I get errors right now. Line 39 is getting me index expected, got string.
http://pastebin.com/iyPUG8XC

Edit: This is when no fluid tanks are connected.

Edited by Cranium, 19 July 2014 - 03:42 PM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 July 2014 - 04:08 PM

It's saying that you're trying to treat a string like a table. The reason "liquid" is getting a string instead of a table is because of the way you built the "liquids" table on line 9.

Change that line to just:

local liquids = {}


#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 19 July 2014 - 05:47 PM

I think I got it. I took your suggestion, and after getting some more errors, I finally set it up to catch the errors.
http://pastebin.com/iyPUG8XC





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users