Accessing user variables in other actors

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!)
Post Reply
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Accessing user variables in other actors

Post by Kzer-Za »

I am trying to check a variable in an actor's master:

Code: Select all

if (master.Damaged)
However the engine gives an error

Code: Select all

Unknown identifier 'Damaged'
I have tried turning it into an actor property in the master:

Code: Select all

bool Damaged;
property Damaged : Damaged;
But the error stays. What am I doing wrong and how should I access variables in other actors?
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: Accessing user variables in other actors

Post by Jarewill »

I am new to ZScript, so I don't know if this is the correct way to do it, but this worked for me:

Code: Select all

let master2 = ActorName(master);
Then check for master2.Damaged instead of master.Damaged.
Replace ActorName with the name of the actor with the Damaged variable.
It doesn't need to be a defined property from what I've seen. Just variables work.
Accensus
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Accessing user variables in other actors

Post by Accensus »

That's how this works, yeah. Properties indeed aren't necessary in this case. They're mainly useful if you're doing inheritance and need certain actors to have different defaults.
Kzer-Za
Posts: 509
Joined: Sat Aug 19, 2017 11:52 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Accessing user variables in other actors

Post by Kzer-Za »

Thanks, it's working!
Post Reply

Return to “Scripting”