Games Support Forums BioWare Info My Account Login Community Sign Up Store
Neverwinter Nights 2 Forums

NWN2: Builders - NWN2 Scripting

New Topic    Post Reply


    Add this To My Topics

   Go To Bottom

Author The scope of variables
KublaKhan1797
Game Owner
Profile: KublaKhan1797NWN
NWN: SoU
Jade Empire:SE
NWN 2
Mass Effect PC


Joined: 03 Jan 2007
Posted: Thursday, 04 January 2007 12:40PM
I have just started scripting a little and I'm rather confused about the scope of variables - or more precisely the difference in scope of global and local variables.

I'm guessing globals are persistent across areas (and modules?) - but what about local variables are they only persistent during the execution of a single script? Also is it necessary to declare a global via SetGlobalXX() or will it automatically be declared with a default value if referred? And when I'm done with a global variable how do I finalize it to prevent memory leakage?

I apologies in advance if this has been asked and answered a thousand times before, I looked about for the information but couldn't find it.
  Profile: KublaKhan1797   Send Message To: KublaKhan1797
ScarfaceDM
Game Owner
Profile: ScarfaceDMNWN
NWN: SoU
NWN: HotU
NWN 2


Joined: 07 Oct 2006
From: From England, Living in Sweden.
Posted: Thursday, 04 January 2007 03:28PM
A standard variable defined outside (and above) any function or void main will be global within that script, a standard variable defined within a function or void main will not be global within that script, it will be usable within the function or void main that it was defined in.

A local variable is stored on an object and is retrievable from any script as long as it exists, they are not persistent unless stored on items in a PCs inventory and then the PCs character exported.

A global variable is not persistent in any way, it is simply 'global', it is not stored on any object thus making it retrievable via its sVarName and not from an object.

A campaign variable is stored in the database folder in your NWN2 directory and also not on any object, and is persistent and retrievable from any script as long as it exists.
_________________
Chaotic World Final
NWVault Hall Of Fame Rank #3
  Profile: ScarfaceDM   Send Message To: ScarfaceDM

New Topic    Post Reply

What do these icons mean?
Where can I learn how to use the forums?

Jump To:

Search Forums | Forums FAQ | Forum Archives

 

 

  Visit the Official Site | Technical Support
Neverwinter Nights 2 Official Support
Hide/Show

English
Deutsch
Français
Español
Italiano

Hide/Show

6,251,297 Users
170 Online
11 Logged In

9,046,484 posts in forums

Newest Forum Topics:
1. These forums are now closed (NWN 1: Scripting)

2. These forums are now closed (NWN2: Guilds and Registry)

3. These forums are now closed (BioWare News Discussion)

4. Can you level items? (NWN 1: Scripting)

5. Thank you! (NWN 1: Scripting)


Current time is: (set time)
Fri, 03 September 2010 12:56AM