Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Do Global Variables Persist?

Edison Swain
Registered User
Join date: 7 Dec 2006
Posts: 51
01-04-2007 16:45
Okay - last question tonight, I promise! :)

I've done some testing, and it seems that they do, but I just want to know if I'm missing anything.

I want to know if the value assigned to a global variable will persist as an object is taken into and back out of inventory.

I know that a state is preserved. What I need to know is whether or not variables are. For example, say I define a global "counter" variable. I set it to zero at the beginning of my script. Then, in the "state_entry" event of every single state in my script, I have the statement:

counter++;

(A trivial example, I know, it just counts how many times the script changes to a different state)

It appears that a variable like this will continue to hold it's present value even as the object is taken in and out of inventory, correct?

So the variable will never get reset to zero unless I specifically set it to zero myself, or the script gets reset for some reason. I'm just hoping that someone can verify this for me.

And finally, can anyone tell me all the different ways that a script can get reset? (intentional or accidental?)

Thanks for much for the help everyone - now I'll be good on my promise and not start anymore threads tonight!
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
01-04-2007 16:51
Yes, the entire state of a script is saved, which includes global variables.

Scripts can be reset by calling the llResetScript() function, or if someone opens up the script and clicks the reset button, or selects "Reset all scripts in selection" from the Tools menu. These last 2 require appropriate permissions. I'm not sure if I know of any other way.
Edison Swain
Registered User
Join date: 7 Dec 2006
Posts: 51
01-04-2007 19:31
From: Ziggy Puff
Yes, the entire state of a script is saved, which includes global variables.

Scripts can be reset by calling the llResetScript() function, or if someone opens up the script and clicks the reset button, or selects "Reset all scripts in selection" from the Tools menu. These last 2 require appropriate permissions. I'm not sure if I know of any other way.


Thanks Ziggy! :)