This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CCJJSax's profile picture

Return Boolean If Cc Peripheral Mod Is Installed

Started by CCJJSax, 08 November 2013 - 09:57 PM
CCJJSax #1
Posted 08 November 2013 - 10:57 PM
I have done some Googling on this (to avoid a recent mistake I made lol) and I couldn't find anything.

I have a specific program that I would like to work with peripheral mods like openperipheral, miscperipheral, Immibis's Peripherals, etc. Some of them have specific functions that I would like to call, but if the user of my program doesn't have that mod, it would crash when that is called.

I probably could do a test thing like this (from the top of my head). But if I can't, or the correct way is really complicated then I think something to test if that mod is there would be useful.


if function() then -- function() being a function specific to that mod
  return true
else
  return false
end

I'm hesitant to actually post this just in case that code is correct, I hate to waste people's time. But it's hard to test without uninstalling mods just to test.
theoriginalbit #2
Posted 08 November 2013 - 11:13 PM
There are few ways that you can check for mods, but really the most effective way is to wrap your peripheral, and if the wrapping returns nil then don't run your program, either the peripheral isn't present, or the peripheral mod isn't present, either way, your program shouldn't run when that peripheral is needed…


local somePeripheral = peripheral.wrap('[name]')
if not somePeripheral then
  error("No [name] attached to this computer", 0)
end

You can even go as far as checking for particular methods

local somePeriph = peripheral.wrap("[name]")
if somePeriph and not somePeriph.someMethod then
  error("[peripheral name] is missing the method [method name] is [mod name] installed?", 0)
end
Edited on 08 November 2013 - 10:53 PM
CCJJSax #3
Posted 08 November 2013 - 11:50 PM
There are lots of ways that you can check for mods, but really the most effective way is to wrap your peripheral, and if the wrapping returns nil then don't run your program, either the peripheral isn't present, or the peripheral mod isn't present, either way, your program shouldn't run when that peripheral is needed…


local somePeripheral = peripheral.wrap('[name]')
if not somePeripheral then
  error("No [name] attached to this computer", 0)
end

You can even go as far as checking for particular methods

local somePeriph = peripheral.wrap("[name]")
if somePeriph and not somePeriph.someMethod then
  error("[peripheral name] is missing the method [method name] is [mod name] installed?", 0)
end

Makes sense to me. This is one of those moments I wish I could lock my own topic.
Lyqyd #4
Posted 09 November 2013 - 04:23 AM
Moved to Ask a Pro.
CCJJSax #5
Posted 10 November 2013 - 02:39 AM
Moved to Ask a Pro.

Good choice ;)/>