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.

Accessing user variables in other actors

Postby Kzer-Za » Sat May 23, 2020 1:20 am

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

Code: Select allExpand view
if (master.Damaged)


However the engine gives an error
Code: Select allExpand view
Unknown identifier 'Damaged'


I have tried turning it into an actor property in the master:

Code: Select allExpand view
bool Damaged;
property Damaged : Damaged;


But the error stays. What am I doing wrong and how should I access variables in other actors?
Kzer-Za
 
Joined: 20 Aug 2017

Re: Accessing user variables in other actors

Postby Jarewill » Sat May 23, 2020 1:27 am

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 allExpand view
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.
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Accessing user variables in other actors

Postby Accensus » Sat May 23, 2020 3:46 am

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.
User avatar
Accensus
Vector, locked in.
 
Joined: 11 Feb 2016
Location: Somalia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Accessing user variables in other actors

Postby Kzer-Za » Sat May 23, 2020 5:29 am

Thanks, it's working!
Kzer-Za
 
Joined: 20 Aug 2017


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests