Jump to content

Photo

How do I fix my global script code to keep draining CR_LIFE until CR_L


  • Please log in to reply
2 replies to this topic

#1 LikeLike888

LikeLike888

    Spicy food lover!!

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

Posted 07 June 2018 - 08:03 PM

If in

import "std.zh"
global script PleaseDrainCR_LIFEUntilZero
{
  void run()
  {
    if (Game->Counter[CR_LIFE]>0)
    {
      Game->DCounter[CR_LIFE] -= 4;
    }
  }
}

I change if to while then my game freezes.



#2 Hari

Hari

    Snivy Gang

  • Members
  • Pronouns:She / Her
  • Location:Idaho

Posted 07 June 2018 - 10:34 PM

Your if statement needs to be in the while loop so that the code is executed each frame.

Also, with the way your code is written, the counter for life will drain faster every frame.

 

This code fixes these issues:

import "std.zh"

global script PleaseDrainCR_LIFEUntilZero
{
  void run()
  {
    while (true)
    {
      if (Game->Counter[CR_LIFE]>0)
      {
        Game->DCounter[CR_LIFE] = -4;
      }

      Waitframe();
    }
  }
}
 

  • LikeLike888 likes this

#3 cavthena

cavthena

    Apprentice

  • Members
  • Real Name:Clayton
  • Location:I wish I knew

Posted 08 June 2018 - 09:09 PM

 

Your if statement needs to be in the while loop so that the code is executed each frame.

Also, with the way your code is written, the counter for life will drain faster every frame.

 

This code fixes these issues:

import "std.zh"

global script PleaseDrainCR_LIFEUntilZero
{
  void run()
  {
    while (true)
    {
      if (Game->Counter[CR_LIFE]>0)
      {
        Game->DCounter[CR_LIFE] = -4;
      }

      Waitframe();
    }
  }
}
 

 

Game->DCounter[]; only needs to be set once. So you do not need a loop to make it drain each frame.

 

Example: Game->DCounter[CR_LIFE] = -16;

 

This will drain 1 life each frame until 16 (1 heart) has been taken.

 

In your code there all your doing is setting the drain amount back to 4 each frame, not draining by 4 each frame. And if the loop were to break the code will take an extra 4hp from Link.

If you want to drain Link's HP by 4 each frame then you need to do this:

import "std.zh"

global script PleaseDrainCR_LIFEUntilZero
{
  void run()
  {
    while (true)
    {
      if (Game->Counter[CR_LIFE]>0)
      {
         Game->Counter[CR_LIFE] -= 4;
      }

      Waitframe();
    }
  }
}

  • LikeLike888 likes this


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users