Having Trouble With ThingCountSector

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Slasher
Posts: 1160
Joined: Sun Mar 16, 2008 11:17 pm
Location: California

Having Trouble With ThingCountSector

Post by Slasher »

I have this script:

Code: Select all

script 916 OPEN
{
   while(ThingCountSector("T_NONE",900,20) > 0)
   {
      Thing_Damage2(900,5-(lightresistpl/10),"LightDamage");
      ACS_ExecuteAlways(917,0,1,5-(lightresistpl/10),0);
      Delay(35);
   }
   Delay(1);
   Restart;
}
This should check to see if the player, who has TID set to 900 in a different script, is in a sector with tag of 20, (that tag number isn't of any importance, could be any number.) and if it greater than 0, meaning the player is in the sector, it should damage them by an amount, every second. The ACS_ExecuteAlways calls a script that adds to an accumulator, not really important as far as the problem I'm having.

The problem is, when I enter the sector, nothing happens. The player is not damaged at all. I've checked to make sure that the sector tag is correct, I've made sure I'm using ThingCountSector correctly according to the information on the wiki. So what am I doing wrong here? I don't see why this shouldn't work...

EDIT: I just realized that I didn't loop the script so it didn't repeatedly check, but I just fixed that and I'm still not getting any difference...so I'm confused again.
Onslaught Six
Posts: 572
Joined: Sun Dec 11, 2005 9:17 pm
Location: Hell.
Contact:

Re: Having Trouble With ThingCountSector

Post by Onslaught Six »

I've never used this function nor done something exactly like this before, but I know of a (simple) way to better test this.

Add some Print command to the inside of the script, like so:

Code: Select all

script 916 OPEN
{
   while(ThingCountSector("T_NONE",900,20) > 0)
   {
      Thing_Damage2(900,5-(lightresistpl/10),"LightDamage");
      ACS_ExecuteAlways(917,0,1,5-(lightresistpl/10),0);
      print(s:"Test 1");
      Delay(35);
   }
   Delay(1);
   print(s:"Test 2");
   Restart;
}
Do that, and then run the level. If it prints the message(s), then it's a problem with Thing_Damage2 and/or ACS_ExecuteAlways. If the first test doesn't print, but the second does, then it's a problem with the While loop.
User avatar
Slasher
Posts: 1160
Joined: Sun Mar 16, 2008 11:17 pm
Location: California

Re: Having Trouble With ThingCountSector

Post by Slasher »

It's even more confusing than that. Maybe I should mention that this was done in a library, outside of the wad that the map is contained in.

I just re-created the scripts within the map itself, and it helped me catch a few errors with the code in my post. First, ACS_ExecuteAlways was screwed up, amongst a few other things.

Code: Select all

script 916 OPEN
{
   while(ThingCountSector("T_NONE",900,20) > 0)
   {
      int damage;
      
      if(lightresistpl > 0 && lightresistpl <= 9)
      {
         damage=5;
      }
      else if(lightresistpl >= 10 && lightresistpl <= 19)
      {
         damage=4;
      }
      else if(lightresistpl >= 20 && lightresistpl <= 29)
      {
         damage=3;
      }
      else if(lightresistpl >= 30 && lightresistpl <= 39)
      {
         damage=2;
      }
      else if(lightresistpl >= 40 && lightresistpl <= 49)
      {
         damage=1;
      }
      else if(lightresistpl == 50)
      {
         damage=0;
      }
      
      Thing_Damage2(900,damage,"LightDamage");      
      ACS_ExecuteAlways(917,0,1,damage,0);
      Delay(35);
   }
   Delay(1);
   Restart;
}

script 917 (int option,int lightresistamount)
{
   if(option==1)
   {
      if(lightresistpl < 50)
      {
         lightresistexp+=lightresistamount;

         while(lightresistexp >= lightresistpl*10)
         {
            lightresistexp-=(lightresistpl*10);
            lightresistpl+=1;
            Delay(1);
         }
      }
   }
   else if(option==2)
   {
      lightresistpl=1;
   }
}
I altered the formula for calculating damage to make it easier to see exactly what damage values should be gotten.

I added this script when testing in my map:

Code: Select all

script 1 ENTER
{
   Thing_ChangeTID(0,900);
   Delay(1);
   Restart;
}
That is basically a condensed version of the initilization script found in the library of my actual project.

Anyway after all that stuff, it worked. It was damaging by the correct amount every second and raising the power level (pl) when it was supposed to. Everything worked properly, so I copied it directly to my library, and now it doesn't work...
User avatar
Slasher
Posts: 1160
Joined: Sun Mar 16, 2008 11:17 pm
Location: California

Re: Having Trouble With ThingCountSector

Post by Slasher »

Here's the map for people who want to test it.

All you have to do is walk into the sector with the sky texture.


Make sure to type "puke 917 2" before entering that sector, to make sure that lightresistpl is set to 1.

On the lower left side of the screen it will print the values of lightresistpl and lightresistexp so you can watch them work as they should.



Since the code in this wad and the code in my library is nearly identical, I don't see why the library code doesn't work. My only guess at this point is that maybe OPEN scripts don't work in libraries. Can anyone confirm this?
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Re: Having Trouble With ThingCountSector

Post by Isle »

T_NONE isn't a string
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Re: Having Trouble With ThingCountSector

Post by Isle »

Code: Select all

script 1 ENTER
{
   Thing_ChangeTID(0,900);
   Delay(1);
   Restart;
}
ow...
User avatar
Slasher
Posts: 1160
Joined: Sun Mar 16, 2008 11:17 pm
Location: California

Re: Having Trouble With ThingCountSector

Post by Slasher »

Ow what? Is there something wrong with that? Hmm....I only had it loop for multiplayer, but since my project no longer supports multiplayer, I don't need it to loop anymore. I'll remove that.


EDIT: Ok after removing the quotes from T_NONE it appears to work...a few more tests though.

EDIT 2: Ok I have it working now. All is fixed.

This raises a question however. T_NONE didn't work in my library script when quoted, so how come it worked quoted in the map wad itself?

Anyway, thanks for the help guys.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Having Trouble With ThingCountSector

Post by Graf Zahl »

Random luck. It's the first string so it got index 0. Library strings get some library ID added and are never 0.
User avatar
Slasher
Posts: 1160
Joined: Sun Mar 16, 2008 11:17 pm
Location: California

Re: Having Trouble With ThingCountSector

Post by Slasher »

Graf Zahl wrote:Random luck. It's the first string so it got index 0. Library strings get some library ID added and are never 0.
Interesting...
Locked

Return to “Editing (Archive)”