logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
suggested function to test NWNX is used

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support
View previous topic :: View next topic  
Author Message
Sir Vendel



Joined: 19 Dec 2015
Posts: 7

PostPosted: Sat Jan 23, 2016 23:06    Post subject: suggested function to test NWNX is used Reply with quote

Hi, all. I am pretty new to NWNX, but I love it increasingly. One function I missed turned out to be rather easy to make, so I post it here, if somone has not thought of it. Enjoy:

//--- prGetUseNWNX -------------------------------------------------------------
//Returns TRUE if NWNX is running, otherwise returns FALSE
int prGetUseNWNX() {
return (NWNXFuncs_GetAreaCount()>0); //All modules have at least 1 area.
} //--- end prGetUseNWNX -------------------------------------------------------
Back to top
View user's profile Send private message
Valgav



Joined: 28 Aug 2010
Posts: 53

PostPosted: Sun Mar 13, 2016 3:04    Post subject: Reply with quote

Where exactly you call that? I use some external call to nwn? There won't be any bridge open if module is not running.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Mar 15, 2016 18:24    Post subject: Reply with quote

Correct me if im wrong.
NWNXFuncs_GetAreaCount() is a member of nwnx_funcs

Surely that only detects if the server has nwnx_funcs available.
Arguably, GetAreaCount is a bad one to use, since in the background it counts the total areas - which could theoretically be hundreds of areas.

Surely

GetFirstArea() would be a better choice (if you are going with a nwnx_funcs) since it relies upon a single area.
It would theoretically run faster than GetAreaCount.

Code:


int IsRunningNWNXFuncs()
{
    return NWNXFuncs_GetFirstArea() != OBJECT_INVALID;
}



If nwnx_funcs is not installed, the method will return OBJECT_INVALID, so by checking it does not equal OBJECT_INVALID, we will know if nwnx_funcs is installed.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Wed Mar 16, 2016 19:54    Post subject: Reply with quote

Baaleos wrote:
Surely that only detects if the server has nwnx_funcs available.
Arguably, GetAreaCount is a bad one to use, since in the background it counts the total areas - which could theoretically be hundreds of areas

no, area count is stored in memory and the plugin only read that number, it does not loop anything and even if it would, nwnx-code is way efficient than anything in nwscript anyway

but you are right this only checks whether nwnx_funcs is in use, however if you are using nwnx_funcs and nwnx_funcs is running then you can assume nwnx is running.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group