Can't read class defaults from a static function?
Moderator: GZDoom Developers
-
- Posts: 537
- Joined: Wed Dec 22, 2021 7:02 pm
- Graphics Processor: Intel (Modern GZDoom)
- Location: Medellin, Colombia
-
- 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?
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.
-
- 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?
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?
-
- Posts: 13837
- Joined: Tue Jan 13, 2004 1:31 pm
- Preferred Pronouns: She/Her
Re: Can't read class defaults from a static function?
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.
-
- 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?
Awesome! Thank you! That's what I was looking for.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.
And here's the wiki page for anyone following along