Jump to content




Return Boolean If Cc Peripheral Mod Is Installed



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

#1 CCJJSax

  • Members
  • 262 posts

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.

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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 by theoriginalbit, 08 November 2013 - 11:53 PM.


#3 CCJJSax

  • Members
  • 262 posts

Posted 08 November 2013 - 11:50 PM

View Posttheoriginalbit, on 08 November 2013 - 11:13 PM, said:

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.

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 November 2013 - 04:23 AM

Moved to Ask a Pro.

#5 CCJJSax

  • Members
  • 262 posts

Posted 10 November 2013 - 02:39 AM

View PostLyqyd, on 09 November 2013 - 04:23 AM, said:

Moved to Ask a Pro.

Good choice ;)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users