Jump to content

Photo

ok somethings not right with my 2 globals

global script help

  • Please log in to reply
17 replies to this topic

#1 Zaxarone

Zaxarone

    Gigi & Merri Superstar Saga

  • Members
  • Real Name:Derek
  • Location:Oregon

Posted 07 February 2016 - 11:15 PM

So i am trying to combine my two global scripts that i am using for my quest but its not working and i really would like to know what im doing wrong and how to fix it. here is my code: (its the pits and lava and the gb shield code)

 

//Include these lines once at the top of your script file.

//import std.zh"
//import ffcscript.zh"
 
//Common Constant, only need to define once per script file.
const int BIG_LINK                  = 0;   //Set this constant to 1 if using the Large Link Hit Box feature.
 
//Constants used by Bottomless Pits & Lava.
const int CT_HOLELAVA              = 128; //Combo type to use for pit holes and lava."No Ground Enemies by default"
const int CF_PIT                   = 98;  //The combo flag to register combos as pits.
const int CF_LAVA                  = 99;  //The combo flag to register combos as lava.
const int WPS_LINK_FALL            = 89;  //The weapon sprite to display when Link falls into a pit. "Sprite 88 by default"
const int WPS_LINK_LAVA            = 90;  //The weapon sprite to display when Link drowns in lava. "Sprite 89 by default"
const int SFX_LINK_FALL            = 38;  //The sound to play when Link falls into a pit. "SFX_FALL by default"
const int SFX_LINK_LAVA            = 55;  //The sound to play when Link drowns in Lava. "SFX_SPLASH by default.
const int CMB_AUTOWARP             = 48;  //The first of your four transparent autowarp combos.
const int HOLELAVA_DAMAGE          = 8;   //Damage in hit points to inflict on link. "One Heart Container is worth 16 hit points"
 
const int SFX_GBSHIELD = 17; //Shield active SFX
 
int shieldItem; //Shield item to give (set by item script, reset each frame)
bool shieldButton; //False = B, True = A
void run(){
//Initializations
bool shieldOn;
//Global variables used by Bottomless Pits & Lava.
int Falling;
bool Warping;
 }
global script slot2_holelava
{
    void run()
    {
        //Initialize variables used to store Link's strating position on Screen Init.
        int olddmap = Game->GetCurDMap();
        int oldscreen = Game->GetCurDMapScreen();
        int startx = Link->X;
        int starty = Link->Y;
        int startdir = Link->Dir;
 
        //Clear global variables used by Bottomless pits.
        Falling = 0;
        Warping = false;
 
        //Main Loop
        while(true)
        {
            Waitdraw();
            if(Link->Action != LA_SCROLLING)
            {
                Update_HoleLava(startx, starty, olddmap, oldscreen, startdir);
                if(Link->Z==0 && !Falling && (oldscreen != Game->GetCurDMapScreen() || olddmap != Game->GetCurDMap()))
                {
                    olddmap = Game->GetCurDMap();
                    oldscreen = Game->GetCurDMapScreen();
                    startx = Link->X;
                    starty = Link->Y;
                    startdir = Link->Dir;
                }
            }
if( !shieldOn && shieldItem ){ //Enable shield when using dummy
shieldOn=true; //Set shield state to on
Link->Item[shieldItem]=true; //Give the shield
Game->PlaySound(SFX_GBSHIELD); //Play the sound
}
else if( ( (shieldButton && !Link->InputA)||(!shieldButton && !Link->InputB)) //When button is released
&& shieldOn){ //And shield is still on
Link->Item[shieldItem]=false; //Remove shield
shieldItem = 0; //Reset shield item variable
shieldOn = false; //Set shield state to off
}
            Waitframe();
        }
    }
}
 
//Handles Pit Combo Functionality.
void Update_HoleLava(int x, int y, int dmap, int scr, int dir)
{
    lweapon hookshot = LoadLWeaponOf(LW_HOOKSHOT);
    if(hookshot->isValid()) return;
 
    if(Falling)
    {
        if(IsSideview()) Link->Jump=0;
        Falling--;
        if(Falling == 1)
        {
            int buffer[] = "Holelava";
            if(CountFFCsRunning(Game->GetFFCScript(buffer)))
            {
                ffc f = Screen->LoadFFC(FindFFCRunning(Game->GetFFCScript(buffer)));
                Warping = true;
                if(f->InitD[1]==0)
                {
                    f->InitD[6] = x;
                    f->InitD[7] = y;
                }
            }
            else
            {
                Link->X = x;
                Link->Y = y;
                Link->Dir = dir;
                Link->DrawXOffset -= Cond(Link->DrawXOffset < 0, -1000, 1000);
                Link->HitXOffset -= Cond(Link->HitXOffset < 0, -1000, 1000);
                Link->HP -= HOLELAVA_DAMAGE;
                Link->Action = LA_GOTHURTLAND;
                Link->HitDir = -1;
                Game->PlaySound(SFX_OUCH);
                if(Game->GetCurDMap()!=dmap || Game->GetCurDMapScreen()!=scr)
                    Link->PitWarp(dmap, scr);
            }
            NoAction();
            Link->Action = LA_NONE;
        }
    }
    else if(Link->Z==0 && OnPitCombo() && !Warping)
    {
        Link->DrawXOffset += Cond(Link->DrawXOffset < 0, -1000, 1000);
        Link->HitXOffset += Cond(Link->HitXOffset < 0, -1000, 1000);
        int comboflag = OnPitCombo();
        SnaptoGrid();
        Game->PlaySound(Cond(comboflag == CF_PIT, SFX_LINK_FALL, SFX_LINK_LAVA));
        lweapon dummy = CreateLWeaponAt(LW_SCRIPT10, Link->X, Link->Y);
        dummy->UseSprite(Cond(comboflag == CF_PIT, WPS_LINK_FALL, WPS_LINK_LAVA));
        dummy->DeadState = dummy->NumFrames*dummy->ASpeed;
        dummy->DrawXOffset = 0;
        dummy->DrawYOffset = 0;
        Falling = dummy->DeadState;
        NoAction();
        Link->Action = LA_NONE;
    }
}
 
ffc script Holelava
{
    void run(int warp, bool position, int damage)
    {
        while(true)
        {
            while(!Warping) Waitframe();
            if(warp > 0)
            {
                this->Data = CMB_AUTOWARP+warp-1;
                this->Flags[FFCF_CARRYOVER] = true;
                Waitframe();
                this->Data = FFCS_INVISIBLE_COMBO;
                this->Flags[FFCF_CARRYOVER] = false;
                Link->Z = Link->Y;
                Warping = false;
                Link->DrawXOffset -= Cond(Link->DrawXOffset < 0, -1000, 1000);
                Link->HitXOffset -= Cond(Link->HitXOffset < 0, -1000, 1000);
                Quit();
            }
            if(position)
            {
                Link->X = this->X;
                Link->Y = this->Y;
            }
            else
            {
                Link->X = this->InitD[6];
                Link->Y = this->InitD[7];
            }
            if(damage)
            {
                Link->HP -= damage;
                Link->Action = LA_GOTHURTLAND;
                Link->HitDir = -1;
                Game->PlaySound(SFX_OUCH);
            }
            Link->DrawXOffset -= Cond(Link->DrawXOffset < 0, -1000, 1000);
            Link->HitXOffset -= Cond(Link->HitXOffset < 0, -1000, 1000);
            Warping = false;
            Waitframe();
        }
    }
}
 
//Used to determine if Link is on a Pit or Lava combo.
int OnPitCombo()
{
    int comboLoc = ComboAt(Link->X+8, Link->Y + Cond(BIG_LINK==0, 12, 8));
    if(Screen->ComboT[comboLoc] != CT_HOLELAVA)
        return 0;
    else if(Screen->ComboI[comboLoc] == CF_PIT || Screen->ComboI[comboLoc] == CF_LAVA)
        return Screen->ComboI[comboLoc];
    else if(Screen->ComboF[comboLoc] == CF_PIT || Screen->ComboF[comboLoc] == CF_LAVA)
        return Screen->ComboF[comboLoc];
    else
        return 0;
}
 
 
//Snaps Link to the combo so he appears completely over pit and lava combos.
void SnaptoGrid()
{
    int x = Link->X;
    int y = Link->Y + Cond(BIG_LINK==0, 8, 0);
    int comboLoc = ComboAt(x, y);
 
    //X Axis
    if(Screen->ComboT[comboLoc] == CT_HOLELAVA && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+1] != CT_HOLELAVA))
        Link->X = ComboX(comboLoc);
    else if(Screen->ComboT[comboLoc+1] == CT_HOLELAVA && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc] != CT_HOLELAVA))
        Link->X = ComboX(comboLoc+1);
    if(Cond(y % 16 == 0, false, Screen->ComboT[comboLoc+16] == CT_HOLELAVA) && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+17] != CT_HOLELAVA))
        Link->X = ComboX(comboLoc+16);
    else if(Cond(y % 16 == 0, false, Screen->ComboT[comboLoc+17] == CT_HOLELAVA) && Cond(x % 16 == 0, true, Screen->ComboT[comboLoc+16] != CT_HOLELAVA))
        Link->X = ComboX(comboLoc+17);
 
    //Y Axis
    if(Screen->ComboT[comboLoc] == CT_HOLELAVA && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+16] != CT_HOLELAVA))
        Link->Y = ComboY(comboLoc);
    else if(Screen->ComboT[comboLoc+16] == CT_HOLELAVA && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc] != CT_HOLELAVA))
        Link->Y = ComboY(comboLoc+16);
    if(Cond(x % 16 == 0, false, Screen->ComboT[comboLoc+1] == CT_HOLELAVA) && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+17] != CT_HOLELAVA))
        Link->Y = ComboY(comboLoc+1);
    else if(Cond(x % 16 == 0, false, Screen->ComboT[comboLoc+17] == CT_HOLELAVA) && Cond(y % 16 == 0, true, Screen->ComboT[comboLoc+1] != CT_HOLELAVA))
        Link->Y = ComboY(comboLoc+17);
}
}
 
void run ( int shield ){
shieldItem = shield;
if ( Link->PressB ) shieldButton = false;
else if ( Link->PressA ) shieldButton = true;
}
 
 

 



#2 Ranagus

Ranagus

  • Members

Posted 08 February 2016 - 04:57 PM

This should compile at least.  Can't say if it works - I didn't test it more than to see that it doesn't crash instantly.

Spoiler

Having the code for global scripts in the top-level function is bad practice because combining them is 'not' a user-friendly procedure, as you found out.  But at least you had the right idea putting all the globals and constants together in the right place.

 

Basically I turned both the global scripts into void functions by removing the global script prefix, replacing it with void and adding () to the end of the script name.  I also removed void run() along with the corresponding pair of brackets.  Then I made my own global script, calling it Main_Loop, and made an infinite while loop including Waitframe(); and my two new functions.  Both scripts had their own infinite loops, so I removed them else only one script would run forever and we would never get to the other.  Now they run together in the bigger loop.  I took away their Waitframes too, because we only need one in the entire script.  Finally, since the scripts are inside functions, I had to move their local variables to the global scope so they don't get reset every frame..

 

You'll need ffcscript.zh if you don't have it, and make sure you're importing them at the top of the file - you the import commands commented out with //

If you don't know how to use a header file, put it in the same folder as ZQuest and have import followed by a space and the name of the file inside "" with the .zh extension.

 



#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 08 February 2016 - 05:32 PM

You had the right idea, but what you did is pretty much...broken. Waitdraw() is not an instruction that should ever be called from with in a function, inside the main infinite loop. It should always be called at the loop level, and your placement will break quite a lot.
 
This is the Nth time for doing this, so I should probably (1) post these containers somewhere that's generally useful, and (2) use the latest version that Tamamo posted to AGN, as this fixes a bug... In the interim, here is the script, properly moved into containers, combined, and moderately optimised.
 

Edited by ZoriaRPG, 08 February 2016 - 06:35 PM.


#4 Zaxarone

Zaxarone

    Gigi & Merri Superstar Saga

  • Members
  • Real Name:Derek
  • Location:Oregon

Posted 08 February 2016 - 05:47 PM

You had the right idea, but what you did is pretty much...broken. Waitdraw() is not an instruction that should ever be called from with in a function, inside the main infinite loop. It should always be called at the loop level, and your placement will break quite a lot.
 
This is the Nth time for doing this, so I should probably (1) post these containers somewhere that's generally useful, and (2) use the latest version that Tamamo posted to AGN, as this fixes a bug... In the interim, here is the script, properly moved into containers, combined, and moderately optimised.
 

 

im getting varible is undeclared errors when i try your script....



#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 08 February 2016 - 05:49 PM

im getting varible is undeclared errors when i try your script....


I don't have ZC on this netbook. If you post the error messages, I'll fix it. I may have missed a call to one of the script vars that I removed. (Unless you didn't fix the import directives, as Ranagus mentioned above.)

Edited by ZoriaRPG, 08 February 2016 - 05:51 PM.


#6 Zaxarone

Zaxarone

    Gigi & Merri Superstar Saga

  • Members
  • Real Name:Derek
  • Location:Oregon

Posted 08 February 2016 - 05:55 PM

http://imgur.com/pDEWODe

 

this is the error i got


im still new to scripting haha trying to understand it better



#7 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 08 February 2016 - 06:26 PM

Try it now:


Edited by ZoriaRPG, 08 February 2016 - 06:35 PM.


#8 Zaxarone

Zaxarone

    Gigi & Merri Superstar Saga

  • Members
  • Real Name:Derek
  • Location:Oregon

Posted 08 February 2016 - 07:08 PM

okay it compiles but the scripts arent working like they should i.e.: the pits dont work and the shield wont come up when i press a or b



#9 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 08 February 2016 - 07:36 PM

okay it compiles but the scripts arent working like they should i.e.: the pits dont work and the shield wont come up when i press a or b


Start a new game save, before anything else: Go to the ZC name entry mode, name a new slot, then open the quest in the new slot.

Edited by ZoriaRPG, 08 February 2016 - 07:37 PM.


#10 Zaxarone

Zaxarone

    Gigi & Merri Superstar Saga

  • Members
  • Real Name:Derek
  • Location:Oregon

Posted 08 February 2016 - 07:53 PM

alright the shield works now but the holes don't



#11 cavthena

cavthena

    Apprentice

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

Posted 08 February 2016 - 08:05 PM

Mero's Pit script is buggy. I don't recommend using it.

 

You could try this one if you wanted.



#12 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 08 February 2016 - 08:50 PM

I can't be sure this is the error you're having, but I believe Mero's pit script requires you to create a falling sprite. It uses the timing of this sprite (number of frames * frame duration) for the core pit functionality. Sprites 89 and 90 are blank unless you put something in them yourself, so both those values will be 0 and the pits won't work correctly.

#13 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 08 February 2016 - 08:54 PM

alright the shield works now but the holes don't


Mero's Pit script is buggy. I don't recommend using it.

You could try this one if you wanted.


No, no... Bugs or otherwise, if they aren't working, it's either because of something that I changed, or it's a problem with (user) implementation.

Did the work, before, at any point in this quest? I need to know if I broke something along the way, or if the OP never had them working.

Edited by ZoriaRPG, 08 February 2016 - 09:00 PM.


#14 Zaxarone

Zaxarone

    Gigi & Merri Superstar Saga

  • Members
  • Real Name:Derek
  • Location:Oregon

Posted 08 February 2016 - 09:10 PM

it worked before. i always had it working. 



#15 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 08 February 2016 - 10:56 PM

it worked before. i always had it working.


I saw one thing that may have affected things...

Here's a minor uodate:


Tell me if that works. be sure that you are assigning global script 'active' to where you previously assigned 'slot2'.



Also tagged with one or more of these keywords: global, script, help

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users