Author Topic: Directional Encounters not working  (Read 394 times)

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Directional Encounters not working
« on: December 28, 2012, 04:32:40 am »


               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.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Directional Encounters not working
« Reply #1 on: December 28, 2012, 05:29:14 am »


               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.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Directional Encounters not working
« Reply #2 on: December 28, 2012, 06:01:40 am »


               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
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Directional Encounters not working
« Reply #3 on: December 28, 2012, 07:56:34 am »


               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");
        }
    }
}
               
               

               


                     Modifié par GhostOfGod, 28 décembre 2012 - 07:59 .
                     
                  


            

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Directional Encounters not working
« Reply #4 on: December 28, 2012, 04:58:59 pm »


               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.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Directional Encounters not working
« Reply #5 on: December 28, 2012, 06:19:34 pm »


               

3RavensMore wrote...

GetObjectByTag needs to start a 0 -- that was the problem.  GetNearestObjectByTag does start at 1 though.

Yeah, quirks of the language, glad you got it resolved.

FunkySwerve wrote...

he's not destroying them midloop - DO has a built-in delay of 0.0, so will execute after the loop.

Good to know.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Directional Encounters not working
« Reply #6 on: December 28, 2012, 10:23:10 pm »


               

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.

D'oh. What I get for giving advice with the toolset closed. Glad you got it resolved. '<img'> I generally still use GNOBT in-area, despite it being slower, to prevent the possibility of mix-ups, but if you're using a unique-tagging system of some kind, there's no objective reason not to use GOBT.

Funky