Jump to content

Globals or locals...?


Kitana

Recommended Posts

It's rare that you see prefixed dialogue state names, which means we can have all sorts of variable collisions for dialogue heavy mods.
Seeing there are even tutorials available from modder(s) that don't care about prefixing their mod variables what can you expect?

Heh, to be fair, prefixing in a tutorial usually means that the folks using your tutorial will use your prefix. I thought Ghrey's complaint that many NPC mods were using J# was pretty funny until I noticed a slew of kit mods using C!. :thumbsup:

 

No kidding.

 

Prefixing everything is the safest way to go, but using that ! in your prefix is a bit of a pain. It can't be used in state labels, so I have to label interjections like

 

I_C_T FILENAME 0 BGavFilename1

== ~B!GavJ~ IF ~InParty("B!Gavin2") InMyArea("B!Gavin2") !StateCheck("B!Gavin2",CD_STATE_NOTVALID)~ ~Doh!~

END

Link to comment
For deciding whether to use locals or glogals, keep in mind that locals are not only bound to one NPC, they are bound to one cre. So, if your character dies and gets resurrected, all locals will be back at 0. In original BGII, romances would be dead if the NPC died, so triggering romance with local variables was feasible, but if you allow your NPC to continue romancing after dieing, using locals would lead to a great chaos.

 

That's absolutely invaluable advice... I think I've just been saved a lot of headaches in the beta testing phase. Thanks!

Link to comment

Glad to hear!

 

Keep in mind that "NumTimesTalkedTo(0)" is a local variable, too. If used in the NPC's greeting dialogue it should be no problem, though, since it switches to the kick-out dialogue once the NPC joined (and as long as he hasn't joined, he can't be resurrected anyhow).

Link to comment
For deciding whether to use locals or glogals, keep in mind that locals are not only bound to one NPC, they are bound to one cre. So, if your character dies and gets resurrected, all locals will be back at 0. In original BGII, romances would be dead if the NPC died, so triggering romance with local variables was feasible, but if you allow your NPC to continue romancing after dieing, using locals would lead to a great chaos.
This is false. Party-joinable characters are stored in the saved game file (GAM) and only change CREs until the first time they join the party. Afterward, the CRE is always restored from the saved game (even if they died and are just resurrected), and all their effects (including LOCALS variables) are appropriately maintained (imagine if you resurrected a character and all their proficiencies were gone!). NumTimesTalkedTo() should similarly be preserved (it's stored in the character headers in the GAM file).

 

The romances broke because there's special code to end them if the character is out of the party or dead for too long, and it didn't ever work very well.

 

For true NPCs, however, your observations are correct (LOCALS and NumTimesTalkedTo() exist independently for every occurrence of a particular CRE, and they won't be preserved if you DestroySelf() a particular CRE and CreateCreature() the same guy for instance).

Link to comment
Party-joinable characters are stored in the saved game file (GAM) and only change CREs until the first time they join the party. Afterward, the CRE is always restored from the saved game (even if they died and are just resurrected), and all their effects (including LOCALS variables) are appropriately maintained (imagine if you resurrected a character and all their proficiencies were gone!). NumTimesTalkedTo() should similarly be preserved (it's stored in the character headers in the GAM file).
This is valuable information to me, thank you! So what I stated above is valid for non-joinable characters. I was imagining having troubles with LOCALS on my NPC but well, I guess I didn't try enough and made false conlcusions after seeing lost locals on non-joinable quest cres.

 

(And I was feeling so proud. Oh well, it's a * ending of a * day.)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...