PDA

View Full Version : An array of FFCs equals....memory overlap?



ScaryBinary
04-19-2008, 03:29 PM
I was experimenting with arrays....just seeing what types of things could be done. In a FFC script (shown below) I declared an array of FFCs and then stepped through the array, setting each FFC's Vx to 1.

On my test screen I had two FFCs; I attached the script to FFC #1, which had a Vx of 0. When the script ran, however, FFC #1 moved across the screen, as if the array I declared in my script were somehow linked to the FFC on the screen! FFC #2 didn't move at all. :odd:

Does this have something to do with the mysterious Declare() function (and the fact that I didn't use it) noted in the release notes for Build 776?

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.
How do I use the Declare() function? What arguments does it take?

Here's the script I wrote:

ffc script ArrayTest{
void run(){
ffc myArray[5];
int index;

// Initialize all the elements
// in the array.
for(index=0; index<5; index++){
myArray[index]->Vx = 1;
}

// Write the array values to
// the logfile.
for(index=0; index<5; index++){
Trace(index);
Trace(myArray[index]->Vx);
}

}

}

*** EDIT ***
After further consideration, I realized my script above is a little...flakey. For instance, I'm setting a FFC attribute (Vx), but I never used the LoadFFC() function to point my FFCs in the array to anything. That's probably 90% of the issue there. Still, the results are mildly interesting....

beefster09
04-19-2008, 06:24 PM
It sounds like it should work; if it didn't, it wouldn't have compiled correctly.

I still haven't messed around with arrays, but I probably will soon.

Joe123
04-19-2008, 06:34 PM
ffc myArray[5]; int i;
for(i=1;i<6;i++){
ffc myArray[i] = Screen->LoadFFC(i);
}

I'd assume you'd want something a bit like that.