Hi, all. I'm pretty new to MEL, but I'm in the middle of making a GUI for one of my scripts, and I've been thoroughly stumped by this problem for hours now. Here is a simple recreation of what I'm trying to do:
{
string $a = "hello";
if (`window -exists myWindow`)
{
deleteUI myWindow;
}
window -title "Window" -widthHeight 100 100 myWindow;
rowLayout -numberOfColumns 1;
button -label "Press Me" -command "foo()" myButton;
setParent ..;
showWindow myWindow;
proc foo()
{
print($a);
}
foo();
}
What's happening is that when foo() is called in the last line, it prints out $a ("hello") no problem. However, when the button's command calls foo(), nothing happens. In fact, sometimes when I was trying this before, it was printing random ascii characters. I even had multiple elements within the window simply try to print the variable's value (a checkbox and an optionMenu) with their command flags, and they printed different values even though nothing was changing the variable.
With some scope research, I found that using the brackets to enclose my entire script would make variables declared at the top of the script accessible to procedures throughout the script (something I thought would be possible by default), but even that's not working. The only solution I've found so far is to make the variable (in this case $a) global. I'd like to try to avoid making it global, but moreso than that, I'd like to know why calling foo() from the button is not printing "hello." Is there something about MEL's scope I'm not understanding, or is it something else?