PDA

View Full Version : Waitframe() and Item Scripts



Praethus
09-17-2007, 01:52 PM
Does Waitframe() work in Item scripts. I have an item that, when used, gives Link access to another item temporarily. I figured the script should look like this.



item script newItem
{
void run()
{
Link->Item[123] = true;
Waitframes(480);
Link->Item[123] = false;
}
}


The first part works, Link gains access to the item. However, he never loses the item.

Help would be greatly appreciated.

C-Dawg
09-17-2007, 02:14 PM
I believe item scripts terminate as soon as they hit Waitframe. So, no.

You have to make a global or ffc script that is triggered by the item use to get any sort of persistent effect out of an item.

Praethus
09-17-2007, 02:36 PM
Ah, C-Dawg, glad to see you back in the game. Zodiac looks good by the way. Yeah, I was looking over how you implemented some of the items in Zodiac.

So if I have the item spawn a FFC with a script attached, can I make it so that it carries over from screen to screen? That way, if Link changes screens or even Dmaps, it will still remove the item at the correct time.

C-Dawg
09-17-2007, 04:52 PM
Glad to see the quest is doing its job of helping inspire people to script! I'm telling ya, everything's possible now.

Yes, you can click the "Carryover" flag on an FFC and it will follow Link. There are some limitations. FFCs stop carrying over when:
(1) Link dies; or
(2) Link is grabbed by a windrobe or wall master.

And FFCs won't carry over if, when Link leaves the screen, the FFC:
(1) Has a combo of 1 (FFC->Data=1); or
(2) Has X or Y coordinates off of the visible screen.

So you need to set up your carryover FFCs on every screen Link can continue or get pulled to by a windrobe/wall master, and ensure that if your FFCs move around via script, they don't ever leave the visible screen.

But as long as you manage all that properly, they work flawlessly.

DarkDragon
09-17-2007, 06:56 PM
(1) Has a combo of 1 (FFC->Data=1); or
Are you sure it's not if combo is 0?

ShadowMancer
09-17-2007, 07:13 PM
(1) Has a combo of 1 (FFC->Data=1); or
Beat me to it DD I was just about to ask that

the way I would write the script: (I personally perfer Global scripts to carryover FFCs, don't know what kind of performance difference there is (if any))



//Global Vars
int ITEM_TIMER = 0;
bool HAS_ITEM = false;


item script newItem
{
void run()
{
Link->Item[123] = true;
ITEM_TIMER = 480;
HAS_ITEM = true;
Waitframe();
}
}

global script main_script{
void run(){
while(true){
Waitframe();
if (HAS_ITEM == true){
if (ITEM_TIMER >0) {
ITEM_TIMER -= 1;
}
else{
HAS_ITEM = false;
Link->Item[123] = false;
}

}
}
}
}

Something like that should work for you :)

Praethus
09-18-2007, 01:08 PM
So do Global Scripts have an implied Waitframe()?

ShadowMancer
09-18-2007, 07:22 PM
oops no they don't I always forget the darn waitfame :rolleyes:
I'll edit in a minute.

Russ
09-18-2007, 07:51 PM
Why can't waitframe just be made to work in item scripts. That way we wouldn't have to make global scripts to acompany the item script. Would make life so much easier for people who love scripting. Who thinks this should be added to things to add to ZC after 2.5?

ShadowMancer
09-18-2007, 08:02 PM
Yeah haveing item scripts with Waitframe would be nice. Although there may be a reason for it working that way that is dependent on the way items work already, if this is true we may have to wait until ZC 3.0 when it gets a whole rewrite and freed of Allegro. IF it is possible I would be all for it post 2.5

Praethus
09-19-2007, 01:59 PM
I was told that Waitframe() doesn't work in Global Scripts because they only last one frame. So how would the above Global Script work?

ShadowMancer
09-19-2007, 07:02 PM
Waitframe works in Global scripts, its Item scripts that last only one frame.
You need to put the global script in global slot 2 (any script put here executes everyframe of the game) I use quite a few global scripts in my quest (well actually its all in one global script but many things happen in that script) As far as I understand FFC and Global scripts work almost exactly the same except that globals are not 'attached' to an FFC object.

Praethus
09-20-2007, 04:40 PM
void Waitframe()
* Temporarily halts execution of the current script. This function
* returns at the beginning of the next frame of gameplay. Global
* scripts and item pickup scripts only execute for one frame, so in
* those scripts Waitframe() is essentially Quit().

I think that needs to be editted then, if Waitframe() works in Global Scripts.

ShadowMancer
09-20-2007, 06:27 PM
Global scripts and item pickup scripts only execute for one frame,
Heh, I never noticed that before, I think DD changed the way Global scripts work recently so that info is outdated. I never tried global scripts before DD's modificatons. So I assume the script worked alright for you?

Praethus
09-21-2007, 12:38 AM
I haven't actually tried it, but if you say Global scripts can use Waitframe() I will try it out. Will make alot of the stuff I'm using much simpler.