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
Returning an error string if specific peripheral not found
Started by Cranium, Jul 19 2014 07:56 AM
6 replies to this topic
#1
Posted 19 July 2014 - 07:56 AM
#2
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
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
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
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.
http://pastebin.com/iyPUG8XC
Edit: This is when no fluid tanks are connected.
Edited by Cranium, 19 July 2014 - 03:42 PM.
#6
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:
Change that line to just:
local liquids = {}
#7
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
http://pastebin.com/iyPUG8XC
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











