Archvile stuck in state loop(?) [Solved]

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)

Archvile stuck in state loop(?) [Solved]

Postby woofdg79 » Sun Jan 09, 2022 11:49 am

Having what I hope is just a simple solution that might need a second set of eyes.

Context is I'm trying to slowly piece together an archvile that uses its hell fire to revive corpses at a distance rather than attack the player. Right now I'm simply trying to get the hell fire to appear over a corpse.

I'm running into an issue where once the archvile spots a corpse, it just stops in its tracks, continuing the walk animation without going anywhere. I have code to print "Found corpse" once it finds one and break out of the loop, but all it does is continually spit out "Found corpse" and never advances to the next piece.

I get this feeling whatever I'm missing is really simple, or a lack of understanding how some of the state logic flows. Below is my current script if anyone wouldn't mind taking a peek. Thanks in advance!

Code: Select allExpand view
class Healvile : Archvile
{
   Actor corpse;
   
   Default
   {
      Speed 15;
      Obituary "Ya done been VILE'ated!!";
      Tag "Healvile";
   }
   
   States
   {
      See:
         VILE A 0; // Dummy frame
         VILE AABBCCDDEEFF 2
         {
            Actor actor;
            ThinkerIterator corpseFinder;
            corpseFinder = ThinkerIterator.Create("Actor");
            corpseFinder.Reinit();
            corpse = null;
            
            while(actor = Actor(corpseFinder.Next()))
            {
               //string msg = "Actor{ Name:"..actor.GetClassName()..", InSight:"..invoker.CheckSight(actor)..", IsMonster:"..actor.bISMONSTER..", CanRaise:"..actor.CanRaise()..", Distance: "..Distance2D(actor).."units }";
               //Console.Printf(msg);
               if(actor.CanRaise() && invoker.CheckSight(actor))
               {
                  corpse = actor;
                  Console.Printf("Found corpse");
                  break;
               }
            }
            
            if(corpse != null)
            {
               A_Jump(256, "HealMissile");
            }
            else
            {
               A_VileChase();
            }
         }
         Loop;
      HealMissile:
         VILE G 0;
         VILE G 10 A_StartSound ("vile/start", CHAN_VOICE);
         VILE H 8 BRIGHT
         {
            if(corpse != null)
            {
               Actor fog = Spawn("ArchvileFire", corpse.Pos, ALLOW_REPLACE);
               if(fog != null)
               {
                  tracer = fog;
                  fog.target = self;
                  fog.tracer = self.target;
                  fog.A_Fire(0);
               }
            }
         }
         Goto See;
      Missile:
         VILE G 0 BRIGHT A_VileStart;
         VILE G 10 BRIGHT A_FaceTarget;
         VILE H 8 BRIGHT A_VileTarget;
         VILE IJKLMN 8 BRIGHT A_FaceTarget;
         VILE O 8 BRIGHT A_VileAttack;
         VILE P 20 BRIGHT;
         Goto See;
      Heal:
         VILE [\] 10 BRIGHT;
         Goto See;
      Pain:
         VILE Q 5;
         VILE Q 5 A_Pain;
         Goto See;
         
   }
}
Last edited by woofdg79 on Sun Jan 09, 2022 12:39 pm, edited 1 time in total.
User avatar
woofdg79
 
Joined: 28 Jan 2015
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Archvile stuck in state loop(?)

Postby Jekyll Grim Payne » Sun Jan 09, 2022 12:14 pm

Jumps need to be return'd. It's also not recommended to use A_Jump* functions and instead use return ResolveState("stateLabel"). See more here.
Last edited by Jekyll Grim Payne on Mon Jan 10, 2022 4:39 am, edited 1 time in total.
User avatar
Jekyll Grim Payne
 
 
 
Joined: 21 Jul 2008
Discord: Agent_Ash#4401
Github ID: jekyllgrim
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Archvile stuck in state loop(?)

Postby woofdg79 » Sun Jan 09, 2022 12:21 pm

Thanks for the quick reply!
I tried "return ResolveState("stateLabel")" before posting this and it gave me an error about a return type mismatch. So I undid that change and posted the original code. Do I need to specify more than just "return ResolveState("stateLabel")"?

Also there is a resource that can help identify these best practices or practices to stay away from? Nothing in the wiki or even the webpage you linked says using A_Jump* is not recommended and in fact uses A_Jump* throughout most of its examples.
User avatar
woofdg79
 
Joined: 28 Jan 2015
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Archvile stuck in state loop(?)

Postby woofdg79 » Sun Jan 09, 2022 12:28 pm

Looks like I also had to include "return ResolveState(null)" at the end of my state's afunc (anonymous function) for the ResolveState in my while loop to work. According to the url you linked once you specify one return route, you need to specify all return routes. That's why I got the type mismatch error.

Thanks for the assistance!
User avatar
woofdg79
 
Joined: 28 Jan 2015
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: Archvile stuck in state loop(?) [Solved]

Postby Jekyll Grim Payne » Mon Jan 10, 2022 4:40 am

Sorry, just fixed the link in my earlier reply :)
Yes, you need to provide a null return at the end, so that the function knows where to go if the first jump condition isn't met.
User avatar
Jekyll Grim Payne
 
 
 
Joined: 21 Jul 2008
Discord: Agent_Ash#4401
Github ID: jekyllgrim
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests