I have this script:
ffc script ItemGen {
void run(int it, int type, int sfx, int d1, int d2, int d3, int d4, int d5) {
//the d? variables change meaning depending on type.
bool fail = true;
while(true) {
if(type == 0) {
//monitoring Screen->D
//d1 is the number of elements
//d2 is the value
fail = false;
for (int i = 0; i < d1; i++) {
if(Screen->D[i] != d2) {
fail = true;
break;
}
}
if(!fail) break;
}
Waitframe();
}
if(Screen->State[ST_ITEM]) return;
Screen->State[ST_ITEM] = true;
item foo = Screen->CreateItem(it);
if(sfx != 0) Game->PlaySound(sfx);
foo->X = this->X;
foo->Y = this->Y;
}
}Simply put, what it does it monitors whatever info you tell it to (currently, only the Screen->D variables), and when the conditions are met, it spawns an item. It then sets Screen->State[ST_ITEM] to true (since you solved the puzzle, got the item, etc), and quits. If, by chance, Screen->State[ST_ITEM] is already set, it won't spawn another item, since it's already been gotten.
It works just fine, except that if the player leaves the screen, and comes back, it will spawn another item. This seems to indicate that Screen->State[ST_ITEM] isn't being saved as it should, or that I'm misunderstanding what it does. It IS read/write, yes? And, it should be saved across screen loads, right?