I have an array that I use to keep track of a set of switches in a series of rooms. The array is created in the header file as follows:
bool switchset[10]
And then, in a certain room file
if (switchset[arrayer] == false) {
switchset[arrayer] = true;
testscore++;
}
However, whenever I enter the room, testscore goes up by one, which means that the value of the switchset has been somehow reset to "false". Any ideas on what could cause this behavior? The arrayer does not change, I've tested it.
EDIT: Just realized, the room this happens in is room number 500. Does this have an effect on the result?
Yes, rooms above 300 don't have their states saved, so it makes total sense.
But isn't the array a global thingamabob, and shouldn't a value I record there stay even if the state of the room is not saved?
Not if you've declared it in the header (as opposed to declaring it in the global script and importing it in the header) - that means it will be instanced for every room.
Okay, so I need to declare the array in the global script, then what?
I'm not sure I'm doing everything right, or even doing everyhting I should. What do I need to do to make the arrays available and editable in the rooms?
int array[20];
in the global script, top of file.
export array[20];
in the global script, end of file.
import int array[20];
in the global header.
Quote from: dkh on Mon 01/02/2010 21:23:24
int array[20];
in the global script, top of file.
export array[20];
in the global script, end of file.
import int array[20];
in the global header.
Ach! Import to header! Thank you all, once again!
Not sure if that compiles, too, but exports usually only need the name:
export array;
Quote from: Khris on Mon 01/02/2010 23:05:57
Not sure if that compiles, too, but exports usually only need the name:
export array;
Realized that when AGS complained, but was too lazy to post a correction. =)
I've got this part working now, and my game is back on track!