Jump to content
  • 0

Script Help Needed - Why does my script terminate?


Wo0p

Question

#library "LastResort.acs"
#include "zcommon.acs"

script "LastResortItem" OPEN
{
	int IfHealth = GetActorProperty(1000, APROP_Health);

	delay(1);
	UNTIL (IfHealth << 1)
	{
		if (CheckActorInventory(1000, "LastResort"))
			SetActorProperty(1000, APROP_Health, 50);
			TakeActorInventory(1000, "LastResort", 1);
	}
}

Hey guys, I'm trying to make a script for an item that prevents you from dying by setting your health back up to 50 when you get below 1 health. But I get the message "Script LastResortItem Terminated" when I'm testing it out ingame.

 

So the script "works" so far as I can launch the game and all that. It just terminates because there's an infinite loop somehow, but I don't see it cos I dont have coder eyes. Please help :D

Edited by Wo0p

Share this post


Link to post

7 answers to this question

Recommended Posts

  • 0

Smaller is "<", not "<<". But the reason your script gets terminated is because it is a "runaway": you did not specify a delay before the next iteration of your loop, meaning it will lock everything else and try run over and over and over within that single gametic. GZDoom detects runaway scripts and terminates those.

 

Specify a delay (eg "delay(8);" as the last line within your loop, meaning your loop will run every other 8 tics instead.

 

That doesn't fix it yet. You determine the value of your monster's health -outside- the loop. Meaning it will always have the same value during the loop. You need to check your monster's health once every loop, so move the "GetActorProperty" line to the condition of your loop.

Share this post


Link to post
  • 0

But then... is there not a delay between the script running? So if you happen to die in a moment it's not running, the item doesn't work. Or does that not matter?

 

It also doesn't work as intended ingame but at least it doesn't terminate now. Thanks for that Mordeth! :D So far so good

 

Any thoughts on how I can make it work?

Edited by Wo0p

Share this post


Link to post
  • 0

Doom tics 34 times per second. A delay of 8 tics means it will check ~4 times per second.

 

Also, do you intend to use this on your player? Don't use SetActorProperty to give the player health, use "HealThing" instead.

 

Edit: "HealThing" only heals the activator of the script (eg the player who picks up the powerup that activates this script).

Share this post


Link to post
  • 0
14 minutes ago, Mordeth said:

Doom tics 34 times per second. A delay of 8 tics means it will check ~4 times per second.

 

Also, do you intend to use this on your player? Don't use SetActorProperty to give the player health, use "HealThing" instead.

 

Ahh ok so basically negligable.

 

Yes I intend for the player to be the user. The item pickup is a powerup giver and the item in the inventory is a CustomInventory actor.

 

EDIT:

Also sorry I didn't see your edited paragraph in your post above. Where do I declare the "int IFHealth=" then if I move the rest of it?

Edited by Wo0p

Share this post


Link to post
  • 0

Also I thought the "UNTIL" part checks the condition before every loop?

Share this post


Link to post
  • 0
8 minutes ago, Wo0p said:

Where do I declare the "int =" then if I move the rest of it?

 

while ( GetActorProperty(1000, APROP_Health) >= 1 ) { ... }

 

Quote

Also I thought the "UNTIL" part checks the condition before every loop?

 

Yes, you check if ifHealth is below a value every time your loop iterates. But you set for ifHeallth to eg 85, and it will be 85 every time since you do not update ifHealth's value.

 

Let me post my "slow heal" powerup, so you can compare notes. This is for the Eternity Engine, but there's enough similarities to get you going.

 

First: the powerup. It sets the script (112 in this case) that will run on pickup in its spawn frames; the script activator will be the player that picks up the powerup.

# ----------------------------------------------------------------------
# PowerUp: HeartSphere
# - Raise player's health by +3 every second for 1 minute.
# - Effect executed by pickup special script
# - Health cannot exceed maxhealth.
# ----------------------------------------------------------------------

spritenames += { HART }

thingtype HeartSphere
{
  basictype = Item
  addflags  = TRANSLUCENT|SUPERITEM
  doomednum = 20138
  xscale    = 0.45
  yscale    = 0.45

  pickupeffect
  {
    effects HeartEffect
    sound heart
    message "\x86A \x85Heartsphere\x86! Your health regenerates!"
  }

  states
  @"
  Spawn:
    HART B    6
    HART C    6 bright SetSpecial(ACS_ExecuteAlways,112,0)
    HART D    6 bright StartScriptNamed(PowerSparkles,2,2,4,0)
    goto Spawned
  Spawned:
    HART ABCD    6 bright
    loop
  "@
}
healtheffect HeartEffect { amount 3; maxamount @maxhealth; +alwayspickup; }

 

And this is the script. Note I do not check the player's current health: this is not needed since HealThing will not heal a dead player. The sound effects will continue on death, but the script will terminate on respawn.

/* -------------------------------------------------------------------------------
** PowerUp: HeartSphere
** - Raise player's health by +3 every second for 1 minute, not exceeding maxhealth
** - Take care of sound clues
** -------------------------------------------------------------------------------
*/
script 112 ( void ) {
    int n0 = 0;
    int max = 59;
    int winddown1 = max - 5;
    int winddown2 = max - 1;

    while ( n0 < max ) {
        delay(35);

        if      ( n0 >= winddown2 ) PlaySound( 0, "dsheart3", CHAN_6);
        else if ( n0 >= winddown1 ) PlaySound( 0, "dsheart2", CHAN_6);
        else                PlaySound( 0, "dsheart",  CHAN_6);

        HealThing( 3, 0 );
        n0++;
    }
}

 

Share this post


Link to post
  • 0

Hmm.. alright I think I get it. I'll fiddle with it some more but you have answered the question of this thread so I'll put a best answer thingy up and then I suppose we'll consider this one closed. If you see another post soon... then I didn't get it. xD

 

Thanks for the answers though! Much appreciated :)

Edited by Wo0p

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...