Write to another script's global variable?
Posted: Sun Apr 30, 2023 10:32 am
Hi. New Dungeon Editor user here. I've hit an issue that I haven't been able to get past and I was hoping someone could help. I am interested in having a "global" script where game-wide variables are stored, such as flags representing player actions and choices. I have been able to read global variables thusly ("globals" is a script object on the map for these examples):
And if I set variables, such as f_undeadFood, from within the global script object, then things work as expected. This includes the variable's state being serialized along with the save game:
However, if I try to assign to the variables from a different script, such as this:
It seems to override an implicit getter with a direct value rather than modifying the actual variable within the global script. This still updates what other scripts see as the variable's value, but the value change is not serialized along with the save game. Instead, saving the game after changing the value in this way produces this warning:
So, is it possible to modify a scripts global variables from a different script? If not, is there any other way to make game-wide global flags? I've already tried this:
Which had basically the same warning when saving the game:
This party.party.* option has some benefit, actually, as it resolves a concern I have about flags being tied to specific maps.
Thanks for any help you can provide.
PS >> I recognize that I could write a setter method for each variable. However, I've written a branching dialogue system, and I expect to have a LOT of flags. Any overhead to flag management is pretty rough.
Code: Select all
if globals.script.f_undeadFood then ...Code: Select all
function toggleUndeadFood()
f_undeadFood = not f_undeadFood;
endCode: Select all
globals.script.f_undeadFood = true;Code: Select all
Warning! Game object property not saved: globals.script._userPropertiesCode: Select all
party.party.f_undeadFood = true;Code: Select all
Warning! Game object property not saved: party.party._userPropertiesThanks for any help you can provide.
PS >> I recognize that I could write a setter method for each variable. However, I've written a branching dialogue system, and I expect to have a LOT of flags. Any overhead to flag management is pretty rough.