PDA

View Full Version : Global Integers in FFC script



Joe123
10-08-2007, 03:02 AM
How do I access global integers in an FFC script?

I can do this right?

Gleeok
10-08-2007, 10:15 AM
int global;

ffc script test{
void run(){
int not global;
while(true){
Waitframes(60);
global++;
not global++;}
}
}


Got it?

Joe123
10-08-2007, 11:34 AM
So I just access it in the FFC script like I would any other integer?
And do I have to declare it within my global script, or just after import "std.zh"?

EDIT: I've tried it just after import "std.zh", and in the global script. It says that it wasn't declared when I did it within the global script, so I assumed that it would be outside the script, when it didn't tell it me it wasn't declared.

So when I try this:


int brac = 0;

ffc script bracelet_warp{ //start script
void run(int map, int scr){ //start void run
while(brac == 0){ //start while loop
if(Link->Item[19] == true){ //start if
Link->PitWarp(map,scr);
int brac = 1;
} //close if
Waitframe();
} //close while loop
} //close void run
} //close script
What I'm thinking it should do is keep checking for whether you have the bracelet every frame, then when you do have it, warp you to another screen, and bump int brac up to 1, ending the while loop; therefore not sending you there again. However, when I reenter the screen, it just keeps warping me. Why should this be?

ShadowMancer
10-08-2007, 12:46 PM
if(Link->Item[19] == true){ //start if
Link->PitWarp(map,scr);
int brac = 1;
you defined a local varible called brac, so take out int
Also, last time I knew checking if Link has an item every frame can cause major slowdown (I think DD said that can't be fixed until ZC 3.0) You might want to do this instead:



int brac = 0;

ffc script bracelet_warp{ //start script
void run(int map, int scr){ //start void run
while(brac == 0){ //start while loop
Waitframe();
} //close while loop
Link->PitWarp(map,scr);
} //close void run
} //close script


item script got_brac{
void run(){
brac = 1;
}
}

Just execute the got_brac script when you pickup the bracelet (set it up in the item editor under the pickup tab)

Joe123
10-08-2007, 01:09 PM
That exact script won't work, because even though you've elimated the while loop, when
you enter the screen after picking up the bracelet, it still warps you before the first frame.

However, when I edited it to look like this:

ffc script bracelet_warp2{ //start script
void run(int map, int scr){ //start void run
while(true){ //start while loop
if(brac == 0){ //start if
brac = 1;
Link->PitWarp(map,scr);
}
Waitframe();
} //close while loop
} //close void run
} //close script

item script got_brac{
void run(){
brac = 1;
}
}

it warps you when you first step onto the screen, then when you step back onto it it doesn't warp you, even when you pick up the bracelet.

ShadowMancer
10-08-2007, 01:15 PM
I had not thought of that, glad you got it woking right :)

Joe123
10-08-2007, 02:04 PM
It infact wasn't working (I did say :confused:)
but anyway, now it is :D

int brac =0;

ffc script bracelet_warp{ //start script
void run(int map, int scr){ //start void run
while(brac <2){ //start while loop
if(brac == 1){ //start if
brac = 2;
Link->PitWarp(map,scr);
}
Waitframe();
} //close while loop
} //close void run
} //close script

item script got_brac{
void run(){
brac = 1;
}
}

Thankyou :)

DarkDragon
10-08-2007, 06:05 PM
Setting inventory is what's slow; checking for an item shouldn't be much slower overall than reading an int.

Best of all of course is to move everything into the item script, and avoid having to busy-loop:



int brac=0;

item script got_brac{
void run(){
if(brac == 0) {
brac = 1;
Link->PitWarp(map,scr);
}
}
}

If there's only one bracelet in your quest you can even get rid of the global variable.

ShadowMancer
10-09-2007, 11:53 AM
I think he wants it to check if Link has the braclet on a specific screen (thus the use of an FFC) If the screen is entered and no braclet, nothing happens but if you do have it you will warp to *wherever* . Not sure but that is what I gathered from the original script. But if you want to warp as soon as you get the braclet DD's script should do the trick with much less code.