Raised This Month: $51 Target: $400
 12% 

How much is expensive LibraryExits?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 11-10-2017 , 13:07   How much is expensive LibraryExits?
Reply With Quote #1

Hi,

I'm asking this since a lot of plugins cache a boolean to check if a certain library exits:
PHP Code:
bool bMyLib;
public 
void OnAllPluginsLoaded()
{
    
bMyLibLibraryExists("bMyLib");
}

public 
void OnLibraryRemoved(const char[] name)
{
    if (
StrEqual(name"MyLib"))
        
bMyLibfalse;
}

public 
void OnLibraryAdded(const char[] name)
{
    if (
StrEqual(name"MyLib"))
        
bMyLibtrue;
}

void MyFunc()
{
      if (
bMyLib)
      {
      
//Code
      
}

So, why I cannot just do:
PHP Code:
void MyFunc()
{
     if (
LibraryExists("bMyLib"))
     {
      
//Code
     
}

I saw a lot of plugins uses the first way, I also use it but "why"?
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 11-10-2017 at 13:08.
Papero is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 11-10-2017 , 18:31   Re: How much is expensive LibraryExits?
Reply With Quote #2

I would suggest this. Use OnLibraryRemoved/OnLibraryAdded if you want to do something at the exact moment a library is added or removed. Use LibraryExists before you want to use a library. Use GetFeatureStatus if you want to check for specific things like if a native exists. Under normal circumstances your examples are both fine to use.
__________________

Last edited by Impact123; 11-10-2017 at 19:30.
Impact123 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-10-2017 , 23:01   Re: How much is expensive LibraryExits?
Reply With Quote #3

I generally just track whether an optional library is loaded globally. This means using OnLibraryAdded, OnLibraryRemoved, and a call to LibraryExists in OnAllPluginsLoaded to catch it if the other plugin loaded first.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode