User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: Importing questions

  1. #1
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,277
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.99%

    Importing questions

    I have a question about importing other scripts. If a script has a Global Variable init, and you use another script to import it, how do you modify said variable without defining it in the script you're importing the other one with? I'm working on an item script that requires two scripts to work, one item script, and one FFC script. The FFC script declares a global variable "Activated", which is modified by the item script. When all if checks return true in the item script, it sets variable Activated to 1 if it's 0, thus letting the FFC script activate, so to speak (It does nothing unless this variable is 1). When used again, it sets the variable to 0 if it's still 1. Basically, the FFC script (the vital part of the item) toggles on and off (so to speak) when the item is used. Now, to my problem. I've imported the FFC half of this item into the Item script half (I do "import 'script_name_here.z'"), but.... When I compile the item script, it always tells me that variable Activated is undefined. I always thought that since the variable is global, ANY script can access it (I import the FFC script for good measure). But that's obviously not true. What am I doing wrong? (By the way, I'm trying to import the FFC script to the item script on the line right after "import 'std.zh'", and it seems that moving the importing to before "void run()" gives ANOTHER compiler error.)

  2. #2
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.55%

    Re: Importing questions

    This should work. Don't forget though that your global variables have to be fully qualified; so if you want to access Activated inside item script foo, you have to say
    Code:
    foo.Activated = 1;

  3. #3
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,277
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.99%

    Re: Importing questions

    Quote Originally Posted by DarkDragon View Post
    This should work. Don't forget though that your global variables have to be fully qualified; so if you want to access Activated inside item script foo, you have to say
    Code:
    foo.Activated = 1;
    So, which script name do I replace "foo" with? The script I'm trying to modify it in (The item script for me), or the script where it's declared (The FFC script)? Oh, and thank you!

  4. #4
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.55%

    Re: Importing questions

    The latter. If that doesn't work, please post both scripts and I'll try to take a look.

  5. #5
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,277
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.99%

    Re: Importing questions

    Quote Originally Posted by DarkDragon View Post
    The latter. If that doesn't work, please post both scripts and I'll try to take a look.
    *sigh* Will do! (Even though I wish for THIS to be a surprise until it's done, though. But then, you'd see it in the end, so...)

    Edit: Well, it's not working. I have no idea why, though. Here's the item script:
    Code:
    // Cane of Byrna (Item)- What? You say we already have an item in ZC called Cane of Byrna? But it doesn't work!
    // That's what this is for. :) This is the item half of the Cane of Byrna. Using this modifies a FFC script to
    // take away 1/4 of a Magic Container for every second this item is in use. That's 8 pieces of Magic.
    
    import "std.zh"
    import "CaneofByrnaFFC.z"
    item script CaneByrnaItem
    {
    	void run()
    	{
    		Link->Item[4] = true;
    		if (CaneByrnaFFC.Activated == 0)
    		{
    			CaneByrnaFFC.Activated = 1;
    		}
    		else CaneByrnaFFC.Activated = 0;
    	}
    }
    ...and the FFC script:
    Code:
    // Cane of Byrna (FFC)- What? You say we already have an item in ZC called Cane of Byrna? But it doesn't work!
    // That's what this is for. :) This is the FFC half of the Cane of Byrna. This half of it is modified by the
    // item half, so that the FFC this is attached to becomes the little "ring" of protection around Link, and
    // Link can't be damaged this way.
    // Changeable Variables:
    // FFCSet- The CSet of the FFC.
    // FFCombo- The first combo the FFC uses.
    // FFCombo2- What combo the FFC reverts to when the item's usage is complete. This is so it doesn't lose any of its Script data. :D
    
    ffc script CaneByrnaFFC
    {
    	int Activated = 0;
    	int FFCSet = 8;
    	int FFCombo = 404;
    	int FFCombo2 = 49;
    
    	void run()
    	{
    		ffc FFCLoad = Screen->LoadFFC(32);
    		while (Activated == 1)
    		{
    			while (Link->MP > 0)
    			{
    				FFCLoad->TileWidth = 3;
    				FFCLoad->TileHeight = 3;
    				FFCLoad->EffectWidth = 48;
    				FFCLoad->EffectHeight = 48;
    				FFCLoad->Data = FFCombo;
    				FFCLoad->CSet = FFCSet;
    				FFCLoad->X = Link->X - 16;
    				FFCLoad->Y = Link->Y - 16;
    				Link->MP -= 8;
    				Waitframe();
    			}
    		}
    		FFCLoad->TileWidth = 1;
    		FFCLoad->TileHeight = 1;
    		FFCLoad->EffectWidth = 16;
    		FFCLoad->EffectHeight = 16;
    		FFCLoad->Data = FFCombo2;
    		FFCLoad->CSet = 0;
    		Activated = 0;
    		Waitframe();
    	}
    }
    As you can plainly see, it's Cane of Byrna. I'm making this because I want to try and help you guys get the Cane working like it's supposed to. See, the problem is, something is going wrong between the point where it checks for variable "Activated". It's either not responding to that variable, or the "Link->MP" variable is broken somehow. After all, it's usually what causes my problems.... ....No wait. After more testing, it seems that only one "while" loop can be done at a time.... What's wrong here? I changed Link->MP in the FFC script to "Timer", and set a value for it, but.... Nothing happened when I used the item script besides getting the Clock item.... I'll check this in the latest beta and get back to you.

  6. #6
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.55%

    Re: Importing questions

    One problem I see immediately is that your FFC script runs once and then immediately quits - it doesn't matter if you toggle Activated, since your FFC script is no longer listening. Don't you want something like while(true) around you whole code?

  7. #7
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,277
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.99%

    Re: Importing questions

    Quote Originally Posted by DarkDragon View Post
    One problem I see immediately is that your FFC script runs once and then immediately quits - it doesn't matter if you toggle Activated, since your FFC script is no longer listening. Don't you want something like while(true) around you whole code?
    Uhh.... I don't really know how to make it loop. I mean, this is basically my first FFC script. I'm too used to Item Scripts. >_<

  8. #8
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.55%

    Re: Importing questions

    ! but you already used a while loop twice...

    Ok, try this:

    Code:
    void run()
       {
          while(true)
    	{
    		ffc FFCLoad = Screen->LoadFFC(32);
    		while (Activated == 1)
    		{
    			while (Link->MP > 0)
    			{
    				FFCLoad->TileWidth = 3;
    				FFCLoad->TileHeight = 3;
    				FFCLoad->EffectWidth = 48;
    				FFCLoad->EffectHeight = 48;
    				FFCLoad->Data = FFCombo;
    				FFCLoad->CSet = FFCSet;
    				FFCLoad->X = Link->X - 16;
    				FFCLoad->Y = Link->Y - 16;
    				Link->MP -= 8;
    				Waitframe();
    			}
                            Activated=0;
    		}
    		FFCLoad->TileWidth = 1;
    		FFCLoad->TileHeight = 1;
    		FFCLoad->EffectWidth = 16;
    		FFCLoad->EffectHeight = 16;
    		FFCLoad->Data = FFCombo2;
    		FFCLoad->CSet = 0;
    		Activated = 0;
    		Waitframe();
    	}
       }
    EDIT: Actually I can see where you're going to have another pretty serious problem in your outer while loop. Fixed in the code above.

  9. #9
    Ultimate Prankster Lucario QDB Manager
    Just registered
    Nimono's Avatar
    Join Date
    Nov 2005
    Location
    Static Void Kingdom
    Age
    32
    Posts
    1,963
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    6,277
    Level
    24
    vBActivity - Bars
    Lv. Percent
    43.99%

    Re: Importing questions

    Thanks, but it's still problematic. For one, it doesn't respond to the effect range and tile range modifications at all, and if you use the item while the FFC script is in effect, it lops of MORE Magic and keeps running!

  10. #10
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.55%

    Re: Importing questions

    OK, I gave your code a thorough going-over and made the following changes. I'll try to explain what I did and why, but let me know if anything here is still confusing:
    Code:
    // Cane of Byrna (Item)- What? You say we already have an item in ZC called Cane of Byrna? But it doesn't work!
    // That's what this is for. :) This is the item half of the Cane of Byrna. Using this modifies a FFC script to
    // take away 1/4 of a Magic Container for every second this item is in use. That's 8 pieces of Magic.
    
    import "std.zh"
    import "CaneofByrnaFFC.z"
    item script CaneByrnaItem
    {
    	void run()
    	{
                    //Link->Item[4] = true;
                    //That would give Link a new clock each time the cane was used,
                    //even when it is turned off. That is clearly not desirable. I moved
                    //the giving of the clock to the FFC script.
    		if (CaneByrnaFFC.Activated == 0)
    		{
    			CaneByrnaFFC.Activated = 1;
    		}
    		else CaneByrnaFFC.Activated = 0;
    	}
    }
    Code:
    // Cane of Byrna (FFC)- What? You say we already have an item in ZC called Cane of Byrna? But it doesn't work!
    // That's what this is for. :) This is the FFC half of the Cane of Byrna. This half of it is modified by the
    // item half, so that the FFC this is attached to becomes the little "ring" of protection around Link, and
    // Link can't be damaged this way.
    // Changeable Variables:
    // FFCSet- The CSet of the FFC.
    // FFCombo- The first combo the FFC uses.
    // FFCombo2- What combo the FFC reverts to when the item's usage is complete. This is so it doesn't lose any of its Script data. :D
    
    ffc script CaneByrnaFFC
    {
    	int Activated = 0;
    	int FFCSet = 8;
    	int FFCombo = 404;
    	int FFCombo2 = 49;
    
    	void run()
    	{
    		ffc FFCLoad = Screen->LoadFFC(32);
                    //This infinite loop is required so that the script doesn't shut down
                    //after the first frame of the game.
    		while (true)
    		{
                            //The stuff in this loop will happen as long as the Cane is
                            //on. The Cane stops being on when Link runs out of magic
                            //or when the player manually toggles it, so we have to
                            //check for both of these exit conditions here.
    			while (Activated == 1 && Link->MP >= 8)
    			{
                                    //As long as the Cane is in use, we have to make sure
                                    //Link keeps the clock.
    				Link->Item[4] = true;
    				FFCLoad->TileWidth = 3;
    				FFCLoad->TileHeight = 3;
    				FFCLoad->EffectWidth = 48;
    				FFCLoad->EffectHeight = 48;
    				FFCLoad->Data = FFCombo;
    				FFCLoad->CSet = FFCSet;
    				FFCLoad->X = Link->X - 16;
    				FFCLoad->Y = Link->Y - 16;
    				Link->MP -= 8;
    				Waitframe();
    			}
                            //Take away Link's clock. Currently this doesn't quite work.
    			Link->Item[4] = false;
    			FFCLoad->TileWidth = 1;
    			FFCLoad->TileHeight = 1;
    			FFCLoad->EffectWidth = 16;
    			FFCLoad->EffectHeight = 16;
    			FFCLoad->Data = FFCombo2;
    			FFCLoad->CSet = 0;
                            //If the above while loop stopped because Link ran out of
                            //magic, we need to turn the Cane off.
    			Activated = 0;
    			Waitframe();
    		}
    		
    	}
    }
    Run the code and you'll see it still doesn't quite work: after turning off the Cane, Link stays invincible for some amount of time until Link's clock runs out. I don't think there's any good workaround for this problem at this time; something like Link->InvincibilityTicks would have to be added.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social