My scripts generally have two main components: A main function followed by the GUI code, all in the same file. I typically use variables that are contained within the Here namespace, get the variables from user input, and call the main function from an 'OK' button box. I don't pass the main function any variables, and just use the variables that were assigned upon the 'OK' button box script. I am considering changing at least one of my scripts so that there is one file with the GUI, and a second file with the main function. Before I do that I am checking how that works within one JSL file. Below is a stripped down example, bypassing the GUI and just defining variables after the function is defined but before it is called.
One thing I've noticed is that it is harder to debug after a script run, because when I hover over the x and y I can see the contents in the status bar at the bottom of the window. But this is not so for the local variables A, B, Z and nw. I wonder if anyone has any tips on this.
I'm also not sure how to access the variable contents from the button box script. If you run the code below you can see that A, B, Z show up in the log as expected (from just before the new window is created), and B and Z also show up in the new window text boxes, but the button box script cannot access these variables directly. I was able to use the eval(parse(eval insert())) to get the array B but I haven't been able to get the string Z. Are there more direct methods for getting this to work?
names default to here(1);
myFun = Function({A, Z},{Default Local},
A[2] = 10;
B = 2*A;
show (A);
show(B);
show(Z);
nw = new window("test",
vlistbox(
textbox(Z),
textbox(char(B)),
buttonbox("Show array B (works)",
show(parse(Eval(Parse(Eval Insert(
"\[^"char(B)"^]\"
)))))
),
buttonbox("Show string Z (does not work)",
show(Eval(Parse(Eval Insert(
"\[^"char(Z)"^]\"
))))
),
buttonbox("show and close (does not work)", show(Z, B); nw << closewindow())
)
)
);
x = [2,3];
y="string";
myFun(x,y);
Thanks,
Mike