PDA

View Full Version : Simple scripting question - life of variables



BeerHunter
Jul 17 2009, 06:08
I'm a total n00b and just trying to learn the scripting language (damn wish it was a simple as C++ :cool:).

Anyway I understand that "_Variable" is local and "Variable" is global.

Question is do (or can) local variables "attach" themselves to an object or are they destroyed when a script exits?

Are global variables accessible throughout the module and have to be user destroyed?

Killswitch
Jul 17 2009, 09:11
Anyway I understand that "_Variable" is local and "Variable" is global.Yes.

Question is do (or can) local variables "attach" themselves to an object or are they destroyed when a script exits?No, yes :-)

You can set and get per-object properties using the commands setVariable (http://community.bistudio.com/wiki/setVariable) and getVariable (http://community.bistudio.com/wiki/getVariable):


// Be happy
player setVariable ["happy", true];

// Set the price of the car
used_car setVariable ["price", 250];

// Get and display the price of the car
hint format ["The car costs %1", used_car getVariable "price"];


Are global variables accessible throughout the module and have to be user destroyed?Yes, global variables are are accessible from all scripts in a mission. One cannot "destroy" variables, but they can be undefined by setting them to nil. See: nil (http://community.bistudio.com/wiki/nil)