Can't read class defaults from a static function?

Moderator: GZDoom Developers

User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Can't read class defaults from a static function?

Post by Sir Robin »

why not?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49190
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Can't read class defaults from a static function?

Post by Graf Zahl »

Static functions have no context from which to access these. They are just like global functions. To access defaults from there you need a class object first that contains their info.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Can't read class defaults from a static function?

Post by Sir Robin »

Graf Zahl wrote: Sat Oct 28, 2023 12:15 pm Static functions have no context from which to access these. They are just like global functions. To access defaults from there you need a class object first that contains their info.
Ok, maye I don't know how it works under the hood. But a default is the same for every instance of a class, right? So even though you're storing it dynamically in code, to Zscript it's static. Woudl it be possible to have a path to these variables as static?

For example every shotgunguy has the same default health, so why can't I use shotgunguy.default.health? Why do I need an instance to view a class default?
User avatar
Rachael
Posts: 13837
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Can't read class defaults from a static function?

Post by Rachael »

If I remember right, you can instantiate a default just by executing YourActorName(GetDefaultsByType(YourActorName)) - the wrapping YourActorName() is an optional typecast that allows you to access its specific scoped variables that are unavailable in the normal actor class.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Can't read class defaults from a static function?

Post by Sir Robin »

Rachael wrote: Wed Nov 01, 2023 12:56 pm If I remember right, you can instantiate a default just by executing YourActorName(GetDefaultsByType(YourActorName)) - the wrapping YourActorName() is an optional typecast that allows you to access its specific scoped variables that are unavailable in the normal actor class.
Awesome! Thank you! That's what I was looking for.

And here's the wiki page for anyone following along

Return to “Closed Feature Suggestions [GZDoom]”