No external local variable references allowed here
Hi
I'm currently working on some UI, ans I'm using a method that I found in Neil Blevins scripts (SoulBurnScripts), which mean everything is in functions, even all the UI items (rollout, buttons, etc...).
So basicaly, for one script I have this:
Script 1:
global theDialog1 -- predefine the dialog local theUI1 -- predefine the function that will create the UI function OpenClose1 = ( try (destroyDialog theDialog1) catch() theUI1() -- call for the function that create the UI createDialog theDialog1 ) function theUI1 = ( rollout theDialog1 ( ... )--end rollout )--end UI function OpenClose1() -- lunch the script
This worked like a charm, no problem here...
Then I tried another method for some tests, which consist to make this script as two separates scripts, so I get this:
Script 1a:
global theDialog1 -- predefine the dialog local theUI1 -- predefine the function that will create the UI function OpenClose1 = ( try (destroyDialog theDialog1) catch() include "C:/Script 1b.ms" theUI1() -- call for the function that create the UI createDialog theDialog1 ) OpenClose()
Script 1b:
function theUI1 = ( rollout theDialog1 ( ... )--end rollout )--end UI function
Also work like a charm...
Where I get my issue is when I try to make another script, that will contain all of the others scripts (all are based on the method explain earlier) I made in one RolloutFloater. So for this one I get this:
global theFloater -- predefine the rolloutFloater local theDialog1 -- predefine first rollout local theUI1 -- predefine first UI maker function local theDialog2 --predefine second rollout local theUI2 -- predefine second UI maker function ... function OpenClose = ( if theFloater != undefined then CloseRolloutFloater sZTFloater include "C:/Script01.ms" theUI1() include "C:/Script02.ms" theUI2() ... theFloater = newRolloutFloater ) OpenClose()
So here, if I use the second method, which consist to split a script in two scripts, with the first one that create the Dialog and call for the UI in the other script, my rolloutFloater work when I call the Script 1b with theUI1()
But If I try with the first method, there I have my issue returned by the listener as:
"compile error: No external local variable references allowed here: theUI1"
I don't really understand why I get this with the first method and not with the second, I would say a variable conflict but I'm really not sure...
So is there a way to avoid this using the first method ?
Do I have to change local variable to global ?
And by the way, I saw in MXS Help that it wasn't that good to use global variable, but which is the better case, multiple script files for only one at the end, or globals variables ?
And two last question (at least for now ^^), does the Neil Blevins method for his scripts is good or not really, and do I use it the right way ?
Ok I think I have finish to write my book... sorry for this big post :)
Comments
Hi, thanks for your answer
Hi, thanks for your answer !
Sorry for my late reply, I'm not at home lately, but I'll check this as soon as I can and keep you inform :)
try using filein. load all
try using filein. load all your function first.I like to use open rollout rather than funtion one. but its only matter of how u writte it.
ex : functiontoLoad=#("a.ms","b.ms"....)
for i in functiontoLoad do filein ("yourpath"+i)
then if your all function succeded you can built a rollout ....
id like using open rollout ex:
ex : a.ms contain :
rollout aa "john"
(
controls etc...
)
...without making it into function. Like
fn makingRollout1 =
(
rollout aa "john"
(
controls etc...
)
)
...well I hope you understand. Btw I want to know why two rollout must be in two different script file ?...why not in one script file special for rollout creator and another file contain only function that will be executed in rollout?
In ms I would like not to use global variable, but if it a must , i would delete it after im using it [usually in script close event], using this method ...
if globalVars.isglobal #YourGlobalName ==true do globalVars.remove #YourGlobalName.