Which is better? To use Global Variables and not have to pass the information in link message (Thus having it always available) or to use local variables and have to pass the information back and forth in link messages to retain access? (See example below)
Lets say you have 2 scripts that communicate via link message. In Script #1 you perform a particular function that needs to go out and have Script #2 do some stuff before Script #1 can finish what it was doing.
I'm going to make up an example here to illustrate my question:
In Script #1 you are in a function called "SetValues". This function does a search on a list to find a given list entry, and then records the index of this entry in a variable called "listIndex". You want to set that index position in the list to the value "15"...whether or not to SET this index position to "15" is determined by certain conditions, and those conditions must be resolved in Script #2. So you call Script #2 with a link message and Script #2 does its thing....and in this example, Script #2 decides that you should indeed set the position in the list indicated by "listIndex" to "15".
So now that Script #2 is finished, it calls back to Script #1 using a link message. But upon returning to Script #1...we don't return to the "SetValues" function where we left off....instead we arrive in the link event-handler of Script #1.
At this point, we need to finish setting the value at listIndex (Which was determined in "SetValues"


So here is the question...
If the variables "listIndex" and the value "15" were variables LOCAL to the "SetValues" function....the only way to hang onto them so that after Script #2 you can STILL set them and STILL have access to them would be to pass those values in the link message to Script #2, and then have Script #2 pass them back again to Script #1 where they will be handled in the link event.
Or....
You could make those same variables "Global" and not have to worry about passing them back and forth between scripts (Especially when Script #2 has no use for those values and just ends up passing them back to Script #1). With those values as "Global" variables they are easily available from the link event where you return to Script #1 at.
Global variables would chew up more memory sitting declared up there to be used whenever, by anyone.
Also....what I don't understand completely...is what if several things happen simulataneously in the script and those global variables must be 'shared'. In the above example...lets say that the above described operation is fired off by an avatar "Touching" the object. Upon touching that object a global variable is set to the Toucher's Avatar Key and that value then goes on to be used by other functions.
What happens if two avatars 'touch' the object in a very short period of time? If the variable is global....is it possible that a subsequent touching avatar's key will replace the key stored in the global variable WHILE it is still being processed?
If a global variable "avatarName" is set to "John Doe" as soon as John touches the object. After setting "avatarName" to "John Doe"....that variable goes on to be used in a bunch of other processing. What happens if "Jane Doe" touches the object before the script is done processing "John Doe"? Will it reset "avatarName" to "Jane Doe" before its done handling John?
I know all of the above was pretty confusing...so please forgive me for any confusion. Hopefully it was enough to get my question across
