Health regen script runaway

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
rollingcrow
Posts: 733
Joined: Tue Mar 02, 2010 8:30 pm
Graphics Processor: nVidia with Vulkan support

Health regen script runaway

Post by rollingcrow »

So while the below problem is fixed, I have another problem. When the player has at least 1 Tenacity item, when it dies the HealthRegen script throws up a runaway script error. Any ideas on why this is happening?

Code: Select all

Script "HealthRegen" ENTER
{
	If (CheckInventory("Dead") == 0)
	Delay(1);
	{
		If (CheckInventory("Pained") == 0)
		{
		If (GetActorProperty(0, APROP_HEALTH) < (CheckInventory("BasicArmor")))
			{
			HealThing(1);
			}
		}
  	}
	Delay(6/StaminaReliance/Tenacity1Power);
 	Restart;
}

Code: Select all

Int Tenacity1Power;

Script "Tenacity1Power" ENTER
{
	If (CheckInventory("Tenacity") > 0)
		{Tenacity1Power = 2;}
	Else If (CheckInventory("Tenacity") == 0)
		{Tenacity1Power = 1;}
	Delay(1);
	Restart;
}

Code: Select all

Int StaminaReliance;

Script "HealthRegenStaminaReliance" ENTER 
{
	If (CheckInventory("StaminaX") >= 2625)
		{StaminaReliance = 4;}
	Else If (CheckInventory("StaminaX") >= 1750)
		{StaminaReliance = 3;}  
	Else If (CheckInventory("StaminaX") >= 875)
		{StaminaReliance = 2;}
	Else If (CheckInventory("StaminaX") >= 0)
		{StaminaReliance = 1;}
	Delay(1);
	Restart;
}
Spoiler: old and resolved problem
Last edited by rollingcrow on Mon Jun 17, 2013 5:51 pm, edited 3 times in total.
User avatar
ChronoSeth
Posts: 1631
Joined: Mon Jul 05, 2010 2:04 pm
Location: British Columbia

Re: Health regen script healing wrong amount

Post by ChronoSeth »

You appear have a stray Delay(1) immediately after the first if in the HealthRegen script. No idea if that's causing the problem.
disposable_username2
Posts: 168
Joined: Tue Mar 08, 2011 1:25 pm

Re: Health regen script healing wrong amount

Post by disposable_username2 »

Se7eNytes wrote:Right now I have a health regeneration script that is supposed to heal 2 HP when the player has the item Tenacity in their inventory, and 1 HP when the player doesn't. However at the moment it is always healing 1 HP regardless of whether or not the player has the Tenacity item or not. Any ideas on why this is happening?
idea: Tenacity1Power is only updated on map changes, so tenacity change won't take effect until next level.
User avatar
rollingcrow
Posts: 733
Joined: Tue Mar 02, 2010 8:30 pm
Graphics Processor: nVidia with Vulkan support

Re: Health regen script healing wrong amount

Post by rollingcrow »

ChronoSeth wrote:You appear have a stray Delay(1) immediately after the first if in the HealthRegen script. No idea if that's causing the problem.
Without it, I'll get a runaway script error. Thanks anyway.
disposable_username2 wrote:idea: Tenacity1Power is only updated on map changes, so tenacity change won't take effect until next level.
Added Restart at the end and it worked. :D
User avatar
rollingcrow
Posts: 733
Joined: Tue Mar 02, 2010 8:30 pm
Graphics Processor: nVidia with Vulkan support

Re: Health regen script runaway

Post by rollingcrow »

Sorry to bump this, but there is a runaway script error happening now when the player dies with tenacity (first post updated).
Blue Shadow
Posts: 5039
Joined: Sun Nov 14, 2010 12:59 am

Re: Health regen script runaway

Post by Blue Shadow »

This line could cause a runaway script, I think:

Code: Select all

Delay(6/StaminaReliance/Tenacity1Power);
If you have a StaminaReliance of 4 and Tenacity1Power of 2, you'll end up with 0.75 as the delay (6/4/2 = 0.75). Now since division in ACS results in an integer, it means that the 0.75 will actually be a 0 (the decimal part is simply truncated). So in that case, you're basically passing 0 as the delay.

Or it could be something else entirely. :P
User avatar
rollingcrow
Posts: 733
Joined: Tue Mar 02, 2010 8:30 pm
Graphics Processor: nVidia with Vulkan support

Re: Health regen script runaway

Post by rollingcrow »

The 6 is now an 8 (8/4/2=1) and now there isn't an error, thanks. :D
User avatar
Mánibranðr System
Posts: 179
Joined: Sun Aug 26, 2012 5:28 pm
Preferred Pronouns: They/Them
Location: Hong Kong

Re: Health regen script runaway

Post by Mánibranðr System »

I think it's better to do the calculation first, pass the result to a newly-declared variable, have a check to see if the result is 0, and if so, change the value to 1, then set the delay to that variable. Or simply do a ceiling division.
Locked

Return to “Editing (Archive)”