PDA

View Full Version : Importing questions



Nimono
02-28-2007, 06:34 PM
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.)

DarkDragon
02-28-2007, 06:59 PM
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


foo.Activated = 1;

Nimono
02-28-2007, 07:00 PM
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


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!

DarkDragon
02-28-2007, 07:54 PM
The latter. If that doesn't work, please post both scripts and I'll try to take a look.

Nimono
02-28-2007, 07:55 PM
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:

// 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:

// 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.

DarkDragon
02-28-2007, 09:09 PM
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?

Nimono
02-28-2007, 09:45 PM
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. >_<

DarkDragon
02-28-2007, 11:55 PM
! but you already used a while loop twice...

Ok, try this:



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.

Nimono
03-01-2007, 12:10 AM
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!

DarkDragon
03-01-2007, 01:29 AM
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:


// 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;
}
}




// 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.

Nimono
03-01-2007, 11:34 AM
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:


// 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;
}
}




// 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.

I'll try it, but I found that 8 pieces of Magic is too much. An entire Magic Meter of 8 Containers would be drained within mere SECONDS. Thus, I believe another Waitframe is needed before the Magic consumption. Or, I could simply do what I did last time I tested it- Changed 8 to 1. That makes it drain slower, but still a bit fast... Oh yes, the reason "Link->Item[4] = false" doesn't work is probably because you don't truly keep the Clock. ....Wow, you'd think that'd be something YOU'D tell ME. XD Anyways, thanks. :) (Did you happen to test this, by the way?)

Edit: Man, it's even WORSE now! For some reason, every time it drains the last bit of Link's magic, it resets his Magic back to full and keeps draining. Plus, by adding more Waitframes..... I found that "Link->MP -= 1" isn't doing what it should. That should drain 1 piece of Magic from Link every time it's called, but instead, it drains A WHOLE CONTAINER! I have no idea what's wrong, but.... It's bad.

DarkDragon
03-01-2007, 06:26 PM
That, my friend, would appear to be a bug in the ZASM script engine. I'll look into it soon.

Nimono
03-01-2007, 08:01 PM
That, my friend, would appear to be a bug in the ZASM script engine. I'll look into it soon.

Can't be. It was working just fine in a previous test, when using the item again took off more magic at a time. :(

DarkDragon
03-04-2007, 08:34 AM
Nope, it's definitely a bug, and amazingly enough it's tied to the way the new init data is set up.
The magic draining problem should be fixed in the next build.

Nimono
03-04-2007, 09:40 AM
Okay, with that out of the way, could you help me here a bit on a note related to the script? When the FFC activates, it's supposed to place a 3x3 FFC around Link (preferrably the same FFC that has the script). Instead of it being 3x3, only a 1x1 16x16 piece of the FFC is changed. Any way to fix this?