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 
 
GetFirst/NextArea

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



Joined: 28 Nov 2007
Posts: 135

PostPosted: Sat Oct 11, 2008 3:33    Post subject: GetFirst/NextArea Reply with quote

Is it wise to set around 5 variables to over half the areas in a module from OnModLoad? I am thinkning to save myself the hassle of going thru each area one by one and setting them.

here is a sample
Code:
#include "nwnx_functions"

void SetUpVariables(object oArea)
{
    if(GetTag(oArea) == "M13_TRF3"){
        }
}
////////////////////////////////////////////////////////////////////////////////
void main()
{
object oArea = GetFirstArea();

    while(GetIsObjectValid(oArea)){
        SetUpVariables(oArea);
    oArea = GetNextArea();
    }
}


is this wise?
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Sat Oct 11, 2008 18:06    Post subject: Reply with quote

Sure, that won't eat up much in the way of cpu. And that's not very many vars. We have at least one set on most of our areas, and MANY more set onarea enter, as part of our encounter system. You might look at doing it onenter area, though, if they're not needed before then.

Funky
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Oct 11, 2008 20:02    Post subject: Reply with quote

You can do it once and then save the module and then open those new module and copypaste all area files (or just those contain variables, not sure which is it now) to your module...
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Extreme



Joined: 28 Nov 2007
Posts: 135

PostPosted: Sun Oct 12, 2008 19:02    Post subject: Reply with quote

That makes sense. I always forget about aareas being static objects. I usually only think of placeables & items.

if I did the extract of the module once those vars are set, will they appear in the vars list when looked at in toolset?

Funky, I'm using mine for encounters mainly as well. but I would rather module loaading be longer then area loading. Is this a wise assmtion?
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sun Oct 12, 2008 22:18    Post subject: Reply with quote

Extreme wrote:
That makes sense. I always forget about aareas being static objects. I usually only think of placeables & items.

if I did the extract of the module once those vars are set, will they appear in the vars list when looked at in toolset?

Funky, I'm using mine for encounters mainly as well. but I would rather module loaading be longer then area loading. Is this a wise assmtion?
Yes and thats the point! I did this way tens waypoints with variables for faster 2da acces.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sun Oct 12, 2008 22:32    Post subject: Re: GetFirst/NextArea Reply with quote

Extreme wrote:
Code:
#include "nwnx_functions"

void SetUpVariables(object oArea)
{
    if(GetTag(oArea) == "M13_TRF3"){
        }
}
////////////////////////////////////////////////////////////////////////////////
void main()
{
object oArea = GetFirstArea();

    while(GetIsObjectValid(oArea)){
        SetUpVariables(oArea);
    oArea = GetNextArea();
    }
}


is this wise?
Anyway. I think it would be more efficient do it this way.
Code:
object GetAreaByTag(string sTag, int nTh=0)
{
int xTh;
object oArea = GetObjectByTag(sTag);
 while(GetIsObjectValid(oArea))
 {
  if(GetIsAreaNatural(oArea)!=AREA_INVALID)
  {
   if(--nTh<0)
   {
   return oArea;
   }
  }
 oArea = GetObjectByTag(sTag,++xTh);
 }
return OBJECT_INVALID;
}


void main()
{
object oArea = GetAreaByTag("M13_TRF3");
SetLocalInt(oArea,"DONTKNOW",TRUE);
//or if you got more areas with the same tag
int n;
 while(GetIsObjectValid(oArea))
 {
 SetLocalInt(oArea,"DONTKNOW",TRUE);
 GetAreaByTag("M13_TRF3",++n);
 }
}
You should spare about tag check count*area count - (area with the same tag+1)*6 instruction.

Smile
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Mon Oct 13, 2008 0:51    Post subject: Reply with quote

Why would he want to use a hacky workaround instead of the function that does EXACTLY what he wants? I can pretty much guarantee the one Extreme wrote is less expensive, to boot.

Funky
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Mon Oct 13, 2008 1:50    Post subject: Reply with quote

FunkySwerve wrote:
Why would he want to use a hacky workaround instead of the function that does EXACTLY what he wants? I can pretty much guarantee the one Extreme wrote is less expensive, to boot.

Funky
Umm thats TRUE...

But my point is, if you know that there are five waypoints in area, why would you count them? Apllied here, if you know you have area with tag "blabla" why would you get through all areas and check them all if their tag is "blabla".

About efficiency, GetFirst/NextArea have to first SetLocalString then GetLocalString and then maybe do some abrakadabra. Someone usualy reliable in this thing told me that calling nwnx is not so fast itself. And if I counting right, my hacky way would be more expensive only if in Extreme function would be only 4if checks (2sure+2for sure).

And sorry for OT, rather send me PM Funky.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Mon Oct 13, 2008 9:00    Post subject: Reply with quote

Locals are lightning fast, and GetObjectByTag crawls. If you want to see the difference, try profiling it in a large mod with thousands of objects. Instead of looping the area list, you're looping a massive object list. His way doesn't require counting waypoints at all, so I'm not sure what you mean. You're going to have to check tag or variable or name, etc to tell between the various areas, so no matter how you loop them you're going to have some additional checks. Those additional checks are, of course, why I suggested an per-area basis via onenter of the area, but they're completely irrelevant when you compare different methods of looping areas, having opted to go that route. And this is certainly not off-topic, since it involves your rather atrocious suggested modification to his perfectly good script. Razz

Funky
Back to top
View user's profile Send private message
Extreme



Joined: 28 Nov 2007
Posts: 135

PostPosted: Mon Oct 13, 2008 12:59    Post subject: Reply with quote

*is learning*
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux 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