View previous topic :: View next topic |
Author |
Message |
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Sat Oct 11, 2008 3:33 Post subject: GetFirst/NextArea |
|
|
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 |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Sat Oct 11, 2008 18:06 Post subject: |
|
|
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 |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sat Oct 11, 2008 20:02 Post subject: |
|
|
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 |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Sun Oct 12, 2008 19:02 Post subject: |
|
|
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 |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sun Oct 12, 2008 22:18 Post subject: |
|
|
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 |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sun Oct 12, 2008 22:32 Post subject: Re: GetFirst/NextArea |
|
|
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.
_________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Mon Oct 13, 2008 0:51 Post subject: |
|
|
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 |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Mon Oct 13, 2008 1:50 Post subject: |
|
|
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 |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Mon Oct 13, 2008 9:00 Post subject: |
|
|
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.
Funky |
|
Back to top |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Mon Oct 13, 2008 12:59 Post subject: |
|
|
*is learning* |
|
Back to top |
|
|
|