PDA

View Full Version : Changing Arguments via Scripting



Sillycat2
06-16-2008, 03:02 PM
In this one script I have, I want to change an FFC's D0 argument during the script.
Is that possible, and how long does it last?
I'd like it to last for the rest of the game.

Gleeok
06-16-2008, 05:49 PM
Currently no. However you can use a dummy item for the time being untill this gets completed. I think it might have something to do with Declare(), which is in there, just not working atm.

edit;


* And finally, the additions of arrays to the scripting engine! Took a lot of work, but they're in. Now, each running script has the option via the global Declare() function to allocate for itself a block of memory. This block of memory is used as a scratch space for declaring and using arrays. One block is continually persistent as a 'global' memory and is used by default when an ffc or item script doesn't declare a piece of memory. Also included is a new section of memory in save files that allows you to store whatever miscellaneous data you like. ( jman2050, 2008-03-04 11:27:42 )

Yep, any day now. :P

ScaryBinary
06-16-2008, 08:04 PM
In this one script I have, I want to change an FFC's D0 argument during the script.
Is that possible, and how long does it last?
I'd like it to last for the rest of the game.

It's not currently possible to alter the D0, D1, ...etc. variables themselves, once the script has started. But you should be able to achieve the same effect using a global variable or one of the Screen->D[] elements. Depending on what you want to do, you might need some additional logic to determine whether or not the script has been called before.

Maybe something like...
// Global copy of D0.
// This will stay whatever you set it to
// for the entire game (even through save/continues).
int Global_D0 = -1;

ffc script MyFFC {
void run(int Initial_D0) {
// Set the Global copy of D0 to the initial value.
// Somehow, you'll have to determine if this is the
// first time the script has been called. I initialized
// Global_D0 to -1, so if it's not -1 then presumably
// the script has been called before...you may need
// to do something different.
if(Global_D0 == -1){
// Do whatever you need to do here the first
// time the script is called...
// ...

// After you do that, set the global value so the next
// time around you skip this portion of code.
Global_D0 = Initial_D0;
}
else {
// This is not the first time the script has been called.
// From this point on, use Global_D0 instead of the
// Initial_D0 that was passed into the function.
// Change it as necessary.
}

}

}

_L_
06-16-2008, 11:59 PM
In this one script I have, I want to change an FFC's D0 argument during the script.
The D registers are actually not used in that way in the ZScript engine. A quote from a source comment:


I will reserve the registers in the following scheme:
SP - stack pointer
D4 - stack frame pointer
D6 - stack frame offset accumulator
D2 - expression accumulator #1
D3 - expression accumulator #2
D0 - array index accumulator
D1 - secondary array index accumulator
D5 - pure SETR sink

Instead, when something like "void run(int toe)" is used, a stack variable for "toe" is declared and input with the initial value for D0.

Gleeok
06-18-2008, 04:01 PM
It's not currently possible to alter the D0, D1, ...etc. variables themselves, once the script has started. But you should be able to achieve the same effect using a global variable or one of the Screen->D[] elements. Depending on what you want to do, you might need some additional logic to determine whether or not the script has been called before.

Maybe something like...
// Global copy of D0.
// This will stay whatever you set it to
// for the entire game (even through save/continues).
int Global_D0 = -1;

ffc script MyFFC {
void run(int Initial_D0) {
// Set the Global copy of D0 to the initial value.
// Somehow, you'll have to determine if this is the
// first time the script has been called. I initialized
// Global_D0 to -1, so if it's not -1 then presumably
// the script has been called before...you may need
// to do something different.
if(Global_D0 == -1){
// Do whatever you need to do here the first
// time the script is called...
// ...

// After you do that, set the global value so the next
// time around you skip this portion of code.
Global_D0 = Initial_D0;
}
else {
// This is not the first time the script has been called.
// From this point on, use Global_D0 instead of the
// Initial_D0 that was passed into the function.
// Change it as necessary.
}

}

}

Apparently GLOBAL_DO will get reset to -1, and won't be saved into the save file. I think jman is fixing that bug with Declare(), though I'm not sure entirely. That's why I mentioned dummy items.

ScaryBinary
06-18-2008, 09:11 PM
Apparently GLOBAL_DO will get reset to -1, and won't be saved into the save file. I think jman is fixing that bug with Declare(), though I'm not sure entirely. That's why I mentioned dummy items.

Huh. I thought I'd used global vars like that before, and they were saved with the game.

Time for a little experiment....:naughty:

*EDIT*
I modified the original script I posted above to dump some stuff to the allegro.log file. Looks like the global variables get saved without getting reset (at least with build 777, but I think also in some previous builds).

My modified script is at the end of this edit. The Initial_D0 was set to 5. The goal of the script was to add 10 to the global variable Global_D0 each time the script executed, but only after the script had been executed once. The value of Global_D0 was dumped to the log file.

For the test, I ran Zelda Classic once, visited the screen the FFC was on 3 times, then Quit and Saved the game (and then exited ZC). What I saw in the logfile was:

5.0000
15.0000
25.0000

I then restarted ZC and did the same thing, and saw this in the logfile:

35.0000
45.0000
55.0000

...so it looks like global vars really do get saved.

My modified script:

// Global copy of D0.
// This will stay whatever you set it to
// for the entire game (even through save/continues).
int Global_D0 = -1;

ffc script MyFFC {
void run(int Initial_D0) {
// Set the Global copy of D0 to the initial value.
// Somehow, you'll have to determine if this is the
// first time the script has been called. I initialized
// Global_D0 to -1, so if it's not -1 then presumably
// the script has been called before...you may need
// to do something different.
if(Global_D0 == -1){
// Do whatever you need to do here the first
// time the script is called...
// ...

// After you do that, set the global value so the next
// time around you skip this portion of code.
Global_D0 = Initial_D0;
}
else {
// This is not the first time the script has been called.
// From this point on, use Global_D0 instead of the
// Initial_D0 that was passed into the function.
// Change it as necessary.
Global_D0 = Global_D0 + 10;

}

Trace(Global_D0);
}

}

Gleeok
06-18-2008, 11:34 PM
Nope, you're right. I just tested this too. Saves fine for me.


The reason I mentioned it was that I thought this had changed recently (since I last tested this a long while back), but it seems the problem is that a few save files for random people in 798 were not saving correctly and/or becoming corrupted. :( not good at all...


I don't know though, I never had that problem.

thebetter1
06-19-2008, 06:59 PM
You can use the global variable method. The other option is for SOMEBODY to ACTUALLY TRY ASM!!! In ZASM, you can write to the d# slots as normal variables.

ScaryBinary
06-19-2008, 07:11 PM
You can use the global variable method. The other option is for SOMEBODY to ACTUALLY TRY ASM!!! In ZASM, you can write to the d# slots as normal variables.

...but would they maintain the value you "manually" set if the script gets called again, or would they get overwritten with the original value set in the Arguments tab of the FFC (or Item)?