Using the global variables in module properties

I defined a global variable via “Edit -> Module Properties -> Advanced”
And then in “Variables” I simply defined a certain int as a global variable.

However, when I try to use that global variable in scripts it tells me that it’s not defined.

What am I missing?

Nothing on NWNLexicon about it. Tried googling, no help.

Storing variables directly on the module object doesn’t automatically make them accessible in all scripts within the module. Module variables can be set up and accessed like this:

    int nCakes = GetLocalInt(GetModule(), "AMOUNT_OF_CAKES");

… and modified the usual way, too:

    SetLocalInt(GetModule(), "AMOUNT_OF_CAKES", 41);


… while constants can be read (but not modified!) from within any function, provided that the constant has previously been declared within that script, or within a library included in the script:

    const int AMOUNT_OF_CAKES = 42;

void OutputCakeMessage(object oTarget)
{
    SendMessageToPC(oTarget, "There is only one acceptable amount of cakes. "+IntToString(AMOUNT_OF_CAKES)+". If we have fewer cakes than that, we are doing something wrong.");
}

int AmountOfCakes()
{
    return AMOUNT_OF_CAKES;
}
1 Like

Thanks! This is a worthy addition to NWNLexicon :slight_smile: I will copy-paste it there unless you have an objection

1 Like