Setup: 1 room with 2 doors. Outside of each door is an Encounter trigger, each with the same tag.
When an Encounter trigger is entered, the Encounter fires as it should, and on the trigger's OnEnter script I have:
void main()
{
if (GetIsPC(GetEnteringObject()))
{
string sEnc = GetTag(OBJECT_SELF);
int n = 1;
object oEncounter = GetObjectByTag(sEnc, n);
while (oEncounter != OBJECT_INVALID) {
SetEncounterActive(FALSE, oEncounter);
DestroyObject(oEncounter);
n++;
oEncounter = GetObjectByTag(sEnc, n);
}
}
}
The only problem is, it doesn't work. When the second Encounter Trigger is entered, the trigger fires as well. It's seems to work *sometimes* but not always. This should be a few steps easier than easy, and on the whole it's a bit embarrassing that I'm struggling with this.
Directional Encounters not working
Débuté par
3RavensMore
, déc. 28 2012 04:32
#1
Posté 28 décembre 2012 - 04:32
#2
Posté 28 décembre 2012 - 05:29
Um, two quick random guesses:
One, shouldn't n start at 0? You might be skipping past the first objectbytag (which might actually be the second encounter) and disabling the triggered encounter. Easiest way to check that is setting n to 0.
Two, by destroying the encounter mid-loop, you might be messing with the getobjectbytag. If encounter A is triggered and is originally 1 (or 0), then once you destroy it encounter B might be considered 1 (or 0), and thus you don't find it because you're looking for two. Easiest way to check that is using a delay command on the destroy object, I suppose.
Don't have time atm to actually test and troubleshoot, should in a few days if it's still an issue.
One, shouldn't n start at 0? You might be skipping past the first objectbytag (which might actually be the second encounter) and disabling the triggered encounter. Easiest way to check that is setting n to 0.
Two, by destroying the encounter mid-loop, you might be messing with the getobjectbytag. If encounter A is triggered and is originally 1 (or 0), then once you destroy it encounter B might be considered 1 (or 0), and thus you don't find it because you're looking for two. Easiest way to check that is using a delay command on the destroy object, I suppose.
Don't have time atm to actually test and troubleshoot, should in a few days if it's still an issue.
#3
Posté 28 décembre 2012 - 06:01
n should not be zero, and he's not destroying them midloop - DO has a built-in delay of 0.0, so will execute after the loop.
Use GetNearestObjectByTag instead - I've seen this kind of issue with GOBT before - it has to do with how the mod finds them - iirc it goes by most recently added, and will give you lots of trouble unless you're very careful with naming conventions. It IS much faster than GNOBT, though.
Funky
Use GetNearestObjectByTag instead - I've seen this kind of issue with GOBT before - it has to do with how the mod finds them - iirc it goes by most recently added, and will give you lots of trouble unless you're very careful with naming conventions. It IS much faster than GNOBT, though.
Funky
#4
Posté 28 décembre 2012 - 07:56
It's been awhile so I'm a bit rusty, and I probably just forgot, but I was under the impression that GetObjectByTag started at position 0. Maybe just put a debug line in the script and see how many it is destroying. Then change the 1 to 0 and see if it makes a difference?
void main()
{
object oPC = GetEnteringObject();
if (GetIsPC(oPC))
{
string sEnc = GetTag(OBJECT_SELF);
int n = 1;
object oEncounter = GetObjectByTag(sEnc, n);
while (oEncounter != OBJECT_INVALID)
{
SetEncounterActive(FALSE, oEncounter);
DestroyObject(oEncounter);
n++;
oEncounter = GetObjectByTag(sEnc, n);
SendMessageToPC(oPC, "Encounter Destroyed");
}
}
}
void main()
{
object oPC = GetEnteringObject();
if (GetIsPC(oPC))
{
string sEnc = GetTag(OBJECT_SELF);
int n = 1;
object oEncounter = GetObjectByTag(sEnc, n);
while (oEncounter != OBJECT_INVALID)
{
SetEncounterActive(FALSE, oEncounter);
DestroyObject(oEncounter);
n++;
oEncounter = GetObjectByTag(sEnc, n);
SendMessageToPC(oPC, "Encounter Destroyed");
}
}
}
Modifié par GhostOfGod, 28 décembre 2012 - 07:59 .
#5
Posté 28 décembre 2012 - 04:58
GetObjectByTag needs to start a 0 -- that was the problem. GetNearestObjectByTag does start at 1 though. It's not to first time I've transposed those two. Thanks everyone for the help.
#6
Posté 28 décembre 2012 - 06:19
Yeah, quirks of the language, glad you got it resolved.3RavensMore wrote...
GetObjectByTag needs to start a 0 -- that was the problem. GetNearestObjectByTag does start at 1 though.
Good to know.FunkySwerve wrote...
he's not destroying them midloop - DO has a built-in delay of 0.0, so will execute after the loop.
#7
Posté 28 décembre 2012 - 10:23
D'oh. What I get for giving advice with the toolset closed. Glad you got it resolved.3RavensMore wrote...
GetObjectByTag needs to start a 0 -- that was the problem. GetNearestObjectByTag does start at 1 though. It's not to first time I've transposed those two. Thanks everyone for the help.
Funky





Retour en haut







