Check if an actor exists?

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!)
Locked
User avatar
Enjay
 
 
Posts: 26957
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Check if an actor exists?

Post by Enjay »

I can see a few threads on this topic, but I can't find anything that definitively answers the question.

Is there a way in ACS to check if an actor actually exists and then only do stuff if the actor is actually real?

Specifically, I'm looking to manipulate the player's inventory and, depending on which mods are loaded, I want it to do different things. However, if mods are not loaded, then certain actors won't even exist as far as the game is concerned, so I don't want to perform operations on non-existant actors.

Code: Select all

if (CheckActorExists("CoolHealthItem") == 1)
      {
            SetHUDSize (640, 480, 0);
            HUDMessageBold (s:"You look like you could use this.";
                  HUDMSG_PLAIN, 44, CR_GREEN, 320.4, 340.0, 3.0);		
            GiveInventory ("CoolHealthItem", 1);
      }
else
      {
            SetHUDSize (640, 480, 0);
            HUDMessageBold (s:"Here, let me patch you up a bit.";
                  HUDMSG_PLAIN, 44, CR_GREEN, 320.4, 340.0, 3.0);		
            HealThing(20);
      }
or something like that.

Possible?
Blue Shadow
Posts: 5040
Joined: Sun Nov 14, 2010 12:59 am

Re: Check if an actor exists?

Post by Blue Shadow »

Last edited by Blue Shadow on Mon Oct 11, 2021 8:50 pm, edited 1 time in total.
User avatar
Enjay
 
 
Posts: 26957
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Check if an actor exists?

Post by Enjay »

Works perfectly, thank you. :)

[edit] And example added to the Wiki https://zdoom.org/wiki/CheckClass_(ACS) [/edit]
Locked

Return to “Scripting”