Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: WHAM on Mon 01/02/2010 20:04:55

Title: Array value resetting, am I missing something obvious?
Post by: WHAM on Mon 01/02/2010 20:04:55
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?
Title: Re: Array value resetting, am I missing something obvious?
Post by: GarageGothic on Mon 01/02/2010 20:42:11
Yes, rooms above 300 don't have their states saved, so it makes total sense.
Title: Re: Array value resetting, am I missing something obvious?
Post by: WHAM on Mon 01/02/2010 20:57:46
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?
Title: Re: Array value resetting, am I missing something obvious?
Post by: GarageGothic on Mon 01/02/2010 21:09:15
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.
Title: Re: Array value resetting, am I missing something obvious?
Post by: WHAM on Mon 01/02/2010 21:22:11
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?
Title: Re: Array value resetting, am I missing something obvious?
Post by: DoorKnobHandle 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.
Title: Re: Array value resetting, am I missing something obvious?
Post by: WHAM on Mon 01/02/2010 22:14:48
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!
Title: Re: Array value resetting, am I missing something obvious?
Post by: Khris on Mon 01/02/2010 23:05:57
Not sure if that compiles, too, but exports usually only need the name:
export array;
Title: Re: Array value resetting, am I missing something obvious?
Post by: WHAM on Thu 04/02/2010 19:43:39
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!