Jump to content

Photo

How do I code if Bait is B Weapon and B Weapon button is pressed Link&


  • Please log in to reply
2 replies to this topic

#1 LikeLike888

LikeLike888

    Spicy food lover!!

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

Posted 04 May 2018 - 11:48 PM

I know I can do

item script BaitTakesLinksHealthBy1IfBaitIsBButtonWeaponAndBIsPressed
{
  void run()
  {
    if (Link->InputB)
    {
      Game->DCounter[CR_LIFE] -= MCounter[CR_LIFE];
    }
  }
}

for example but just in case I ever need an FFC or global script for multiple frames of stuff happening if an item is B Weapon button item and B weapon button is pressed something happens.

 

 

 

Please tell me in either FFC or global or both script how I would code if Bait is B Weapon Item and B Weapon button is pressed Link's health is drained by one heart. Thank you.



#2 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 06 May 2018 - 09:59 AM

When you're using an item script, you generally don't need to check if B is pressed, because that's what makes the script start running in the first place.
 
item script DrainAHeart
{
    void run()
    {
        Link->HP-=16; // 16 HP = 1 heart
    }
}
If you want an FFC or global script to do something when the item it used, don't try to detect it by watching for the button to be pressed. It's cumbersome and unreliable. Use an item script as the trigger.

For the global script, use a global variable to communicate.
 
bool BaitWasUsed;

item script Bait
{
    void run()
    {
        BaitWasUsed=true;
    }
}

global script BaitGlobal
{
    void run()
    {
        BaitWasUsed=false; // Reset it each life
        
        while(true)
        {
            if(BaitWasUsed)
            {
                // Do stuff
            }
            Waitframe();
        }
    }
}
For an FFC script, you can use ffcscript.zh to make the item script start the FFC script.
 
ffc script Bait_ffc
{
    void run()
    {
        // Do whatever
    }
}

item script Bait_item
{
    void run()
    {
        int scriptName[]="Bait_ffc";
        int scriptNum=Game->GetFFCScript(scriptName);
        RunFFCScript(scriptNum, NULL); // Sets up an FFC and runs the script with no arguments
    }
}


#3 LikeLike888

LikeLike888

    Spicy food lover!!

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

Posted 06 May 2018 - 07:54 PM

Thank you so very much Saffith




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users