PDA

View Full Version : Deprecation notice: global variables



DarkDragon
05-27-2007, 01:29 AM
In preparation for a planned overhaul of the ZScript language in 2.5, I have changed the syntax of global variables slightly, as per several of your suggestions. Global variables should now be declared at file scope, instead of at script scope.
Old syntax:


ffc script foo {
int a=3;
//...
}

ffc script bar {
void run() {
this->X = foo.a+5;
}
}

New syntax:


int a = 3;

ffc script foo {
//...
}

ffc script bar {
void run() {
this->X = a+5;
}
}


This new syntax is recommended for all new scripts, and the old, script-scope syntax is deprecated. What does this mean?
1) Quests containing scripts which are already compiled, and which will never need to be modified and recompiled, are completely unaffected.
2) Incomplete quests containing scripts which do need to be recompiled will still compile - for now. The ZScript compiler will issue a warning pointing out where in your scripts you have used the old syntax, but will nevertheless compile your script.

How long will the old syntax still work? Until I need to reuse that syntax for a new language feature (such as "class-scope" variables visible to all instances of a specific script), which certainly won't be until after b18.

I apologize for this change, and the inconvenience of having to modify old scripts you wish to reuse, but unlike most other parts of ZQ, maintaining perfect backwards compatibility in the ZScript language is not feasible. I've tried and will try to minimize changes such as this one which require modification of old scripts, will give you as much of a "grace period" as possible to change over old scripts, and am happy to help anyone who has trouble porting their old scripts to the new syntax.

C-Dawg
05-27-2007, 03:01 AM
Good with me. I only use global variables in one script anyway, for now.

C-Dawg
05-27-2007, 09:15 PM
Your new global variables don't work, nor does 319 correctly run code compiled under previous versions. Download Zodiac over at the Quest forum and try running it under 319.

(1) The jumping script does not function at all. Not sure what's going on with it.

(2) I tried moving all the variables used by the jump function outside of script, as per your example. It doesn't compile. Gives me an error, saying that it didn't expect a declaration there.

DarkDragon
05-27-2007, 09:56 PM
I know the jumping doesn't work, but that has nothing to do with the global variables; grab the next-to-latest beta and you'll see. Actually, if you have any idea where I might start in investigating this bug, I'd be very thankful, as I want Zodiac to be one of the quests working perfectly in b18.

Are you sure about the errors? I just copied and pasted the block of variable declarations to outside of the ffc declaration and it compiled with no warnings or errors.

C-Dawg
05-27-2007, 10:31 PM
(1) If it's not the variable scope change, what is causing the script to malfunction in later betas? As near as I can tell, the jump script is just not ever getting out of the state where link's position is reset to offset _L_'s gravity. Normally this state stops once the airtime variable expires. For some reason, that's not happening. And until the player touches the ground again, the one_jump variable (preventing you from jumping, releasing the button to descend, and then hitting the button again to keep moving upwards because your airtime hadn't expired) doesn't reset and you can't continue jumping. If you end up on the same plane as a platform though, you can walk over to it, and then one_jump resets normally. So it's definitely a problem with the "okay the jump is done now let gravity take over" variable.

Perhaps it's a bug with the sideview gravity, actually?

(2) I didn't declare the variables with values; just int i; int j; that kind of thing. Is that allowed? If so, maybe there's a silly syntax error in there somewhere... I'll check.

DarkDragon
05-27-2007, 11:33 PM
Yes, that should be allowed. Here's your scripts, after my modifications:



import "std.zh"

int jumpforce_maximum; // The maximum force of the player's jump.
int jumpforce_current = 0; // The current foir
int i = 0; // Counters for smoothing top of jump
int j = 0;
int k = 0; // switch for jump smoothing

int floaty_maximum; // Maximum value for floaty.
int floaty = 0; // This counter ensures the player floats
// briefly at the height of the jump.
int dashing = 0; // 0 = not dashing, 1 = dashing
int MP_refill = 0; // counter for continuous MP refill
int airtime = 0; // This counter controls the time of the jump.
int airtime_current = 0; // This is the player's present airtime.
int resist = 0; // conuter to increasing gravity

int turnoffjump = 0; // turns off jumping once player
// releases the jump button in the air.
int prev_jump = 0; // was link jumping the frame before?

int double_jumped = 0; // keeps track of the number of jumps for double-jumping


// =================================
// Jump - This script handles the following:
// Jumping, Dashing, Energy refill
// Currently uses whistle for double jump,
// Roc's Feather for high jump.
// =================================

ffc script Jump{


void run(){

... rest of the code


As you can see all I did was move the variables over and delete some tabs for readability.

I will investigate in-depth why your jump script is failing.

Majora
05-27-2007, 11:41 PM
Sideview is broken in 319, and if I remember correctly, has been since 303 (I think)

_L_
05-28-2007, 02:40 AM
That it has been! But I fixed it just now. Now everything mentioned in this topic works again!