Kiefer Beckett
Confused
Join date: 22 Jun 2004
Posts: 106
|
05-03-2005 18:01
Are global variables global to all instances of the same script or to each instance of the script?
The reason I ask is I put the same script in two objects but changed the values of the globals and each behaved the same instead of using its own values.
in object1, I created a script called move float X_DISTANCE = 0; float Y_DISTANCE = 7; float Z_DISTANCE = 0;
int object2, I copied script move to it and changed the variables to these values float X_DISTANCE = 0; float Y_DISTANCE = 17; float Z_DISTANCE = 0;
then I have a third object that told the object1 and object2 to move by sending text via a channel. Each object was moved themselves the distance in Y_DISTANCE. I was expecting that object1 move 7 meters and object2 move 17 meters but they both moved 17 meters.
So thats why I ask: Are global variables global to all instances of the same script or to each instance of the script?
thnx Kiefer
_____________________
A tired mind become a shape shifter Everybody need a mood lifter [Rush - Vital Signs]
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
05-03-2005 18:44
a global variable is sandboxed to the current script. Scripts do not share memory.
So if you set the variable in one instance of the script it will only change in that one instance.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
05-03-2005 19:56
What Strife said. Check to make sure you don't have some listeners or the like conflicting.
I will note, however, that there are some *very VERY rare* bugs where functions from scripts with the same key affect each other. That doesn't seem to be the case here, though.
_____________________
---
|