Array value resetting, am I missing something obvious?

Started by WHAM, Mon 01/02/2010 20:04:55

Previous topic - Next topic

WHAM

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:
Code: ags
bool switchset[10]


And then, in a certain room file
Code: ags

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?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

GarageGothic

Yes, rooms above 300 don't have their states saved, so it makes total sense.

WHAM

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?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

GarageGothic

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.

WHAM

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?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

DoorKnobHandle

Code: ags

int array[20];


in the global script, top of file.

Code: ags

export array[20];


in the global script, end of file.

Code: ags

import int array[20];


in the global header.

WHAM

Quote from: dkh on Mon 01/02/2010 21:23:24
Code: ags

int array[20];


in the global script, top of file.

Code: ags

export array[20];


in the global script, end of file.

Code: ags

import int array[20];


in the global header.

Ach! Import to header! Thank you all, once again!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Khris

Not sure if that compiles, too, but exports usually only need the name:
Code: ags
export array;

WHAM

Quote from: Khris on Mon 01/02/2010 23:05:57
Not sure if that compiles, too, but exports usually only need the name:
Code: ags
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!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

SMF spam blocked by CleanTalk