As the title says, is it possible to take a global variable, change the value in the room script, and then use the changed variable back in the global script?
header
int iCharAct[23]; // header declaration
room script
iCharAct[17] = 1; // changing value in room script
Global Script
if (iCharAct[17] == 1)
{
player.Say("1"); // should say this if iCharAct[17] is 1, but he doesn't
}
The player should say "1" if iCharAct[17] was changed properly, but somewhere it was dropped. Any way to fix this or am I not allowed to change variables in the room script?
Thanks.
You are making a classic mistake (people get into this problem every now and then).
AGS Script works like this: everything found in the script headers is being copied to each of the script modules (including room ones).
So when you declare a variable in the header like this, you actually create multiple non-connected variables, one per each module and per each room.
To make it work properly, in AGS script's header you need to declare an "import" of a variable:
import int iCharAct[23]; // header declaration
This declaration means that there is ONE instance of variable somewhere.
Then in the Global script itself you need to actually create and export this variable:
int iCharAct[23];
export iCharAct;
This means that you are making this one variable available for use in other modules under such name.
More information about these keywords may be found in the manual: http://www.adventuregamestudio.co.uk/manual/ags46.htm#importkeyword
Seems awfully long-winded but it worked, thanks!