Jump to content

Photo

My Entire ZScript freezes my game how do I change it to work as I need


  • Please log in to reply
1 reply to this topic

#1 LikeLike888

LikeLike888

    Spicy food lover!!

  • Members
  • Real Name:Jason
  • Location:North America

Posted 05 June 2018 - 06:43 PM

import "std.zh"
int ActivateDrainLinkHPToZeroScript = 0;
item script IfPotion1BlueIsBWeaponItem
{
  void run()
  {
    while (Game->Counter[CR_LIFE]!=0) //as long as life is not equaling 0
    {
      ActivateDrainLinkHPToZeroScript = 1; //make ActivateDrainLinkHPToZeroScript active
    }
  }
}
//v used on Active:
global script DrainLinkHPToZeroScript
{
  void run()
  {
    while (ActivateDrainLinkHPToZeroScript == 1) //as long as ActivateDrainLinkHPToZeroScript = 1
    {
      while(Game->Counter[CR_LIFE]!=0) //as long as life is not equaling to 0
      {
        Game->DCounter[CR_LIFE] = -4; //drain life by one fourth of a heart
        Game->PlaySound(23); //play Refill sound
      }
    }
  }
}
//v Used only onExit: and onContinue:
global script MakeActivateDrainLinkHPToZeroScriptEqualToZero
{
  void run()
  {
    ActivateDrainLinkHPToZeroScript = 0; //ActivateDrainLinkHPToZeroScript make up above global script no longer become used because ActivateDrainLinkHPToZeroScript is equaling to 0 instead of 1
  }
}

 

 

 

What exactly must I change up above code so that in global script while

ActivateDrainLinkHPToZeroScript is equaling 1 LIFE gets drained by one fourth of a heart until Link's HP is equal to 0?



#2 Saffith

Saffith

    IPv7 user

  • Members

Posted 05 June 2018 - 07:27 PM

Generally, a while loop should have a Waitframe() in it.
When this runs:
    while (Game->Counter[CR_LIFE]!=0) //as long as life is not equaling 0
    {
      ActivateDrainLinkHPToZeroScript = 1; //make ActivateDrainLinkHPToZeroScript active
    }
The game won't do anything else except run that block of code over and over until Link's HP hits 0. Since nothing in that block affects Link's HP, it will keep running forever. Waitframe() tells the game to stop running the script and do other things, then come back to the script in the next frame.

However, item scripts only run for one frame. A Waitframe() in an item script will make the script quit running entirely. But you don't need a loop there at all; you only need to set the variable once to trigger the global script.

The global script loop also needs a Waitframe(). Setting Game->DCounter[CR_LIFE] doesn't affect Link's HP directly, so that one will also loop forever.
  • Anthus likes this


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users