Jump to content

Photo

My TryThisGlobalScriptPlease freezes my game and Link does not appear


  • Please log in to reply
4 replies to this topic

#1 LikeLike888

LikeLike888

    Spicy food lover!!

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

Posted 12 June 2018 - 06:28 PM

Here:

 
import "std.zh"
int Gobi = 1;
int BluePotionInUseForDeath = 0;
int AlarmForBluePotionDeath = 0;
int HealthLinkHas = 12;
int MaximumAlarmForBluePotionDeath = 1;
item script BluePotionUseForDeath
{
  void run()
  {
    BluePotionInUseForDeath = 1;
  }
}
global script TryThisGlobalScriptPlease
{
  void run()
  {
    while (Gobi == 1)
    {
      if (BluePotionInUseForDeath == 1)
      {
        Link->X += 0;
        Link->Y -= 0;
        Link->X -= 0;
        Link->Y += 0;
        if (Game->Counter[CR_LIFE] == 0)
        {
          Link->Item[29] = false;
        }
        else if (Game->Counter[CR_LIFE] != 0)
        {
          if (AlarmForBluePotionDeath != MaximumAlarmForBluePotionDeath)
          {
            if (AlarmForBluePotionDeath == 0)
            {
              MaximumAlarmForBluePotionDeath = Game->Counter[CR_LIFE];
              AlarmForBluePotionDeath += 4;
            }
            else if (AlarmForBluePotionDeath > 0)
            {
              Game->DCounter[CR_LIFE] -= 4;
              Game->PlaySound(23);
              AlarmForBluePotionDeath += 4;
            }
          }
        }
      }
    }
  }
}

is my code. Please tell me how to fix it so the game does not get frozen at all. Thank you



#2 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 12 June 2018 - 08:17 PM

There's no waitframe in the while loop. All while loops should have a waitframe.



#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 13 June 2018 - 09:28 AM

There's no waitframe in the while loop. All while loops should have a waitframe.

 

All infinite loops.

 

Here:

 

is my code. Please tell me how to fix it so the game does not get frozen at all. Thank you

 

 

import "std.zh"
int Gobi = 1;
int BluePotionInUseForDeath = 0;
int AlarmForBluePotionDeath = 0;
int HealthLinkHas = 12;
int MaximumAlarmForBluePotionDeath = 1;
item script BluePotionUseForDeath
{
    void run()
    {
        BluePotionInUseForDeath = 1;
    }
}
global script TryThisGlobalScriptPlease
{
    void run()
    {
        while (Gobi == 1)
        {
            if (BluePotionInUseForDeath == 1)
            {
                Link->X += 0;
                Link->Y -= 0;
                Link->X -= 0;
                Link->Y += 0;
                if (Game->Counter[CR_LIFE] == 0)
                {
                    Link->Item[29] = false;
                }
                else if (Game->Counter[CR_LIFE] != 0)
                {
                    if (AlarmForBluePotionDeath != MaximumAlarmForBluePotionDeath)
                    {
                        if (AlarmForBluePotionDeath == 0)
                        {
                            MaximumAlarmForBluePotionDeath = Game->Counter[CR_LIFE];
                            AlarmForBluePotionDeath += 4;
                        }
                        else if (AlarmForBluePotionDeath > 0)
                        {
                              Game->DCounter[CR_LIFE] -= 4;
                              Game->PlaySound(23);
                              AlarmForBluePotionDeath += 4;
                        }
                    }
                }        
            }
            Waitdraw();
            Waitframe();
        }
    }
}


#4 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 13 June 2018 - 11:56 AM

All infinite loops.

It's better to teach the rule first, then the exception. 

also I did tell him that last time but it happened again so I'm clarifying for his further usage until he gets better



#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 14 June 2018 - 08:36 AM

It's better to teach the rule first, then the exception. 

also I did tell him that last time but it happened again so I'm clarifying for his further usage until he gets better

 
...except that it's the other way around.
 
I find that it's better to explain what an infinite loop is, if the reader is unaware, and to teach why this stuff is required, rather than issuing blanket statements.

 

Honestly, I sometimes feel as if the world is all gone quite mad
 

[...]


Here are some while loop examples:
 

int NotInfiniteLoop()
    int x = Rand(100)+1; int n; int n2;
    while(n < x ) ++n2; // This while loop runs until the condition is met (evaluates false).
    return n2;
}
 
void InfiniteLoop()
{
    int n;
    while(1 == 1) // This condition always evaluates true, so the loop never ends.
    {
        ++n; // Will increase forever. ZC seems to hang, because this loop runs infinitely in ONE FRAME of GAME ACTION!!
                 // ZC does not actually crash, but it is never given the chance to advance a frame.
    }
}
 
void InfiniteLoopWithWait()
{
    int n;
    while(1 == 1) //this condition always evaluates true, so the loop never ends.
    {
        ++n; Waitframe();
         // Will increase forever. but only ONE INCREMENT *PER FRAME* of game action!
         // Now, ZC does not seem to hang, but this loop never exits.
    }
}
    
void InfiniteLoopWithBreakCondition()
{
    int n;
    while(1 == 1) // This condition always evaluates true, so the loop never ends.
    // We usually express this as while(true0 or while(1), as in either case, the condition in the statement
    // always evaluates as 'true'. In this case, i used an *expression* to facilitate the point.
    {
        ++n;
        if ( n > 600 ) break; // No longer infinite, because the loop will break.
    }
}
 
int InfiniteLoopWithReturn()
{
    int n;
    while(true) // This condition always evaluates true, so the loop never ends.
    {
        n += Rand(60);
        if ( n > 600 ) return n; // No longer infinite, because the loop will break when it returns a value!    }
}
   
int NonInfiniteLoopWithWait
{
    bool a = true;
    while(a) //runs until a == false
    {
        if ( Link->HP <= 0 )
        {
            a = false; // Link's HP falling beneath '1' causes the loop to break by unsetting the condition.
        }
        Waitframe(); // Each loop cycle occurs in ONE FRAME of GAME ACTION!
    }
    return Link->HP;
}

        

 
 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users