Actor UserVariables not saved in ZDS

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
DnB-Freak
Posts: 304
Joined: Sun May 19, 2013 12:09 pm

Actor UserVariables not saved in ZDS

Post by DnB-Freak »

I'm trying to make a dynamic healthbar over here using actor uservars and map scripts.
There are some information which is not saved in the .zds and only when custom monsters are involved.

Technical:
The healthbar is shown in integer numbers XXX / XXX health.
When pointing on a monster the global script displays the health on the screen as a hud.
Actors health can be manipulated via map scripts like the following code:

Code: Select all

Script 1 OPEN
{
	SetActorProperty(3, APROP_HEALTH, 352);
	SetActorProperty(4, APROP_HEALTH, 404);
	SetActorProperty(5, APROP_HEALTH, 606);
}
Because APROP_SPAWNHEALTH is for players only it cannot be used as a solution.
To define a max health and make the map script to do it is possible using this method in DECORATE for each monster:

Code: Select all

ACTOR ZombieMan2: ZombieMan replaces ZombieMan 3004
{
	var int user_MaxHealth;
	States
	{
	Spawn:
		POSS AA 1
		POSS A 0 A_SetUserVar("user_MaxHealth", Health)
	Idle:
		POSS AB 10 A_Look
		Loop
	}
}
The Spawn state defines the max health that can be extended via a map script that is executed BEFORE the uservariable is set,
this explains the 2 tic delay at the start of the spawn.
The rest of the time the monster will return to Idle state, not spawn, so the healthbar limits can only be set once, but are never saved in zdoom savegame files *.zds.

Debugging
Run
demo.wad
Example
(4.27 KiB) Downloaded 33 times
Feel free to take a look inside the WAD for relevant information.
There is a custom monster called SmartShotgunGuy which doesn't replace any original monster.
Patch the demo on DOOM2.WAD and simply run it despite skill.

Kill the imp and the save the game.
Press the switch and target at the SmartShotgunGuy in the middle, his health starts with 606, set via scripting.
Then die by letting them shot you or write "kill" in the console.
Your recent save is loaded. Now pull the switch again and target the SmartShotgunGuy again, his health not starts on 92, not 606.
The other monsters are OK so this error seem to affect only custom monsters.

What happened? The map script was executed after the save, but the actor's decorate Spawn state was never entered,
showing of the spawnhealth given to the script not the health passed over first time.

Analysis appreciated.
Have best wishes to get it fixed.
User avatar
Nightfall
Posts: 555
Joined: Thu Aug 06, 2009 4:00 am
Location: Finland

Re: Actor UserVariables not saved in ZDS

Post by Nightfall »

In my experience APROP_SpawnHealth has worked perfectly fine for non-players too.
DnB-Freak
Posts: 304
Joined: Sun May 19, 2013 12:09 pm

Re: Actor UserVariables not saved in ZDS

Post by DnB-Freak »

Nightfall wrote:In my experience APROP_SpawnHealth has worked perfectly fine for non-players too.
Do you mean:
SetActorProperty(1, APROP_SPAWNHEALTH, 999); ?

I've tested this about 20 times for several different monsters, doesn't do anything at all.
Which build version do you use btw?
ZzZombo
Posts: 317
Joined: Mon Jul 16, 2012 2:02 am

Re: Actor UserVariables not saved in ZDS

Post by ZzZombo »

Nightfall wrote:In my experience APROP_SpawnHealth has worked perfectly fine for non-players too.
It only gets the spawn health of an actor, but can't set it for non-players.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Actor UserVariables not saved in ZDS

Post by Graf Zahl »

Chickenlegz wrote:
Nightfall wrote:In my experience APROP_SpawnHealth has worked perfectly fine for non-players too.
Do you mean:
SetActorProperty(1, APROP_SPAWNHEALTH, 999); ?

I've tested this about 20 times for several different monsters, doesn't do anything at all.
Which build version do you use btw?

Well, obviously. The spawn health is a class property which cannot be altered for single actors.
DnB-Freak
Posts: 304
Joined: Sun May 19, 2013 12:09 pm

Re: Actor UserVariables not saved in ZDS

Post by DnB-Freak »

Graf Zahl wrote:
Chickenlegz wrote:
Nightfall wrote:In my experience APROP_SpawnHealth has worked perfectly fine for non-players too.
Do you mean:
SetActorProperty(1, APROP_SPAWNHEALTH, 999); ?

I've tested this about 20 times for several different monsters, doesn't do anything at all.
Which build version do you use btw?

Well, obviously. The spawn health is a class property which cannot be altered for single actors.
Yes, I know that :( Thats why I had to workaround and use uservars to create a fake spawn health which could be altered in ACS from certain maps.
Unfortunately this doesn't work properly. I'm not quite sure if it's actually a bug, however the actors uservars seems lost after save game.
Loading the uservars via script from a saved game afterwards returns nullified values.
It can be proved in the attached demo. Please, let me know, Thanks in advance.
User avatar
Fishytza
Posts: 793
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: Actor UserVariables not saved in ZDS

Post by Fishytza »

I think I found the culprit behind your problem. SmartShotgunGuy inherits from ShotgunGuy2. Both actors define user_MaxHealth or rather ShotgunGuy2 defines it and SmartShotgunGuy redefines it. (Because he already has it just by inheriting from ShotgunGuy2.)

I commented out "var int user_MaxHealth" in SmartShotgunGuy's actor definition and then ran your test (kill imp, save game, press switch, die, load save). Things seemed to work as expected, IE SmartShotty's health was still 606/606 after loading the save.
User avatar
edward850
Posts: 5889
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Actor UserVariables not saved in ZDS

Post by edward850 »

There is, however, still an actual problem with serializing uservars, because that suggests that the keys are overwriting each other while still being able to exist independently in the playsim. One of these needs to change (probably the latter, as there is no reason why two keys with the same name in the same class should exist).
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Actor UserVariables not saved in ZDS

Post by Graf Zahl »

Ah, of course that kind of variable name duplication should not be allowed.
This will produce a compile error now.
DnB-Freak
Posts: 304
Joined: Sun May 19, 2013 12:09 pm

Re: Actor UserVariables not saved in ZDS

Post by DnB-Freak »

FishyClockwork wrote:I think I found the culprit behind your problem. SmartShotgunGuy inherits from ShotgunGuy2. Both actors define user_MaxHealth or rather ShotgunGuy2 defines it and SmartShotgunGuy redefines it. (Because he already has it just by inheriting from ShotgunGuy2.)

I commented out "var int user_MaxHealth" in SmartShotgunGuy's actor definition and then ran your test (kill imp, save game, press switch, die, load save). Things seemed to work as expected, IE SmartShotty's health was still 606/606 after loading the save.
wow, just that? It's might an user error after all.
and I thought uservariables couldn't be inherited or overridden.
Thanks very much, Fishy, problem solved.
Post Reply

Return to “Closed Bugs [GZDoom]”