Check if a specific addon is enabled?
Is there a way to check for this?
I ask as I am trying to integrate support for Item Saver in my Bank Manager Revived. Item Saver uses a global variable which I pull (ItemSaver_IsItemSaved(item.bag, item.slot)), It returns 1 if the checked item is saved, otherwise nil. I made that work fine, but when Item Saver is not enabled in AddOns, then I get a "function expected instead of nil" error. So... I guess I need to make sure Item Saver is enabled in AddOns before even running this check. Can this be done? |
Quote:
Lua Code:
This is a function which I use in Dustman: lua Code:
|
you probably can check if the checkbox is checked in the addon panel, but I think it would be simpler to check if the function exists before calling it.
Code:
if(ItemSaver_IsItemSaved ~= nil) then ItemSaver_IsItemSaved(item.bag, item.slot) end |
@sirinsidiator: I tried that solution and it also threw the same error.
@Garkin: Your solution worked (as always). Thanks to both of you for the suggestions :banana: |
Hi.
In the Wiki is stated, that a callback of EVENT_ADD_ON_LOADED is called for all addons. This is the reason why we always have to check for our own addon name. Isn't that exactly what you need? Cheers |
Quote:
Just add the addon to your OptionalDependsOn and then Lua Code:
I actually used a version of this for Advanced Filters to create a filter for Item Saver before I changed the way filters could be added. |
However, consider that Garkin's gets directly to the point: Is the required function there?
If an addon doesn't have any global functions, you're not going to be using one of its functions in your addon. |
Just to clarify:
As I wrote in my initial post then I wanted to check if Item Saver was enabled, so my addon can take advantage of it's functions, but not fail if Item Saver is not even installed. Problem was solved with Garkin's answer. |
Quote:
The question was "Check if a specific addon is enabled?", not "Check if a global function is available?". There are scenarios, where "Always-check-before-calling" is absolutly sufficient. And there are scenarios, where such a check should be done once and different functions are registered to be called. Mainly if used in large, nested loops. Quote:
Sorry. :( |
All times are GMT -6. The time now is 04:36 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI