GetActorProperty APROP_SpawnHealth broke?

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
Zhs2
Posts: 1303
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere
Contact:

GetActorProperty APROP_SpawnHealth broke?

Post by Zhs2 »

Confirmed using r1857 and 2.3.1. Apparently, attempting to set the player's maximum health using SetActorProperty APROP_SpawnHealth has a strange effect. The player cannot pick up health restoring items that don't raise health above max, such as Medikits and Stimpacks, after having SetActorProperty called on him.

Relevant code:

Code: Select all

#library "sadface"
#include "zcommon.acs"

script 868 (void)
{
    int maxhealth = GetActorProperty(0, AProp_SpawnHealth);
    SetActorProperty(0, AProp_SpawnHealth, maxhealth+1);
} 
My first attempt, didn't work either:

Code: Select all

script 868 (void)
{
    SetActorProperty(0, AProp_SpawnHealth, (GetActorProperty(0,AProp_SpawnHealth)+1));
} 
A compiled version of the top code. Run, "]puke 868", and "]summon medikit". "]Take health 1" and attempt to pick up for further proof.
sadface.pk3
Last edited by Zhs2 on Sun Sep 20, 2009 5:57 pm, edited 1 time in total.
User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: SetActorProperty APROP_SpawnHealth broke?

Post by HotWax »

Did you bother to check the value of maxhealth after assigning it the return value from GetActorProperty? I suspect GAP is returning 0 (which may or may not be a bug...) and so you're setting the player's new max value to 1. Of course that means that as long as the player is alive, he's at or higher than his max health, so only those items which are allowed to go over that would work.

You can test the value of maxhealth by plugging in a print statement:

Code: Select all

script 868 (void)
{
    int maxhealth = GetActorProperty(0, AProp_SpawnHealth);
    print (i:maxhealth);
    SetActorProperty(0, AProp_SpawnHealth, maxhealth+1);
}
User avatar
Zhs2
Posts: 1303
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere
Contact:

Re: GetActorProperty APROP_SpawnHealth broke?

Post by Zhs2 »

Admittedly, I did not think of that. A quick insert of that line does indeed reveal that the maxhealth variable is equal to zero. Fortunately, changing the topic to reflect that only required one character...!

Fixed test attached. =(
sadface.pk3
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: GetActorProperty APROP_SpawnHealth broke?

Post by Graf Zahl »

You can't assume that this property is set. 0 is a default setting that translates to 'use the default', meaning, the value being set in Dehacked or 100. If you want to work with AProp_Spawnhealth you have to initialize it first to a meaningful start value or add special handling for the 0-case.
User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: GetActorProperty APROP_SpawnHealth broke?

Post by HotWax »

So basically this script could be fixed very easily:

Code: Select all

script 868 (void)
{
    int maxhealth = GetActorProperty(0, AProp_SpawnHealth);
    if (maxhealth == 0) maxhealth = 100;
    SetActorProperty(0, AProp_SpawnHealth, maxhealth+1);
}
And you're done.
User avatar
Nash
 
 
Posts: 17505
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: GetActorProperty APROP_SpawnHealth broke?

Post by Nash »

I never knew 0 was the default. I have been using this for a very long time, but it always worked because for some reason I did remember to initialize it (without even knowing what I was doing) in my startup scripts...

This is some useful information!
User avatar
Zhs2
Posts: 1303
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere
Contact:

Re: GetActorProperty APROP_SpawnHealth broke?

Post by Zhs2 »

And now I know. [wiki=ACS_actor_properties]Fix'd the wiki entry.[/wiki]

Do I have to initialize APROP_SpawnHealth just once for a game, or do I have to do it every map? This is a library script, and I ask because I have another method of stating its initial value, but the way it is set up means only setting it from the first map...
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: GetActorProperty APROP_SpawnHealth broke?

Post by Graf Zahl »

The safest bet is to do it every map but only if GetActorProperty returns 0. If the value is already set you shouldn't change it.
User avatar
Zhs2
Posts: 1303
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere
Contact:

Re: GetActorProperty APROP_SpawnHealth broke?

Post by Zhs2 »

Thanks for the reply. I did some tinkering and testing with this for a bit, and found that there isn't TOO much problem between map changes and the APROP_SpawnHealth property.

Speaking of tinkering, I also found out that setting a player.maxhealth property for a playerclass seems to initialize the APROP_SpawnHealth property just as setting it with SAP would; however, the default Doomplayer doesn't have a player.maxhealth property -- nor do the other playerclasses for the other games as I browse through zdoom.pk3, it seems. Might be intended, though, if we had to uncover what we did in this topic... =P
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: GetActorProperty APROP_SpawnHealth broke?

Post by randi »

Graf Zahl wrote:0 is a default setting that translates to 'use the default', meaning, the value being set in Dehacked or 100
I suppose the non-Doom classes could have proper values, though, since they can't use Dehacked patches.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: GetActorProperty APROP_SpawnHealth broke?

Post by Graf Zahl »

Please don't ask me what the actual motivation was here. I didn't write that code. It was a code submission. But that assumption is not true. deh.MaxHealth is not a player class property but global. And Dehacked patches can be loaded in all games.
Post Reply

Return to “Closed Bugs [GZDoom]”