Jump to content
Sign in to follow this  
crashdome

Local variables

Recommended Posts

OK...can't find ANYTHING on this, which I am surprised..BUT:

from Official Reference

Quote[/b] ]Local variable is any variable which name starts with underscore. All other variables are global.

Each of commands then, do, while, forEach, count, exec, call defines a visibility scope for local variables. All local variables from outer scopes are visible as well. If assignment is made into a variable that does not exist in any visible scope, it is created in the innermost scope. You can use function private to introduce variable at any given scope.

therefore (in theory) I should be able to call a script

and assign

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_NUM=1

[] exec "innerscript.sqs"

and innersript.sqs was

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_NUM=2

after that (still in original script) calling _NUM to screen should output "2"

right?

Share this post


Link to post
Share on other sites

I tried

[_NUM] exec "Innerscript.sqs"

also... no luck on bringing that variable into the inner scope.

Share this post


Link to post
Share on other sites

Once started with exec, scripts always run independently from everything else and can only "modified" by using global variables (i.e. no underscore). A script can thus be never within the scope of another script.

The scoping comes into play when using stuff like functions (I think the official Reference is a little misleading mentioning the exec). This should work:

_NUM = 1

call {_NUM = 2;}

format["%1",_NUM] --> 2

Share this post


Link to post
Share on other sites

After rereading the local variable paragraph above, I came to understand just what you said. By scope, they mean either the "[ ]" or "{ }" used to call them and not necessarily the script or function itself.

Thanks for your confirmation.

In the words(or action) of my favorite Looney Toons character:

"Back to the drawing board."

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×