Buuuuut, when I run this exact same script in my MEL GUI it always returns true and won't toggle? What gives, I must be missing some secret formatting or something?
//This always returns true which is the exact same code in a window global proc button20UVmapper () { int $uvToggleChecker = !$uvToggleChecker; if ($uvToggleChecker == 1) { print ("UV checker map turned on."); }
you need to understand the scope of a variable. in a proc the variable is local, thus you always initialized it with the same value. you need a global variable to remember the state.
also good to understand variable declaration, which answers your problem with previous thread, you were declaring it twice.
Thanks guys, I'm just learning MEL so I don't really understand the rules yet and I'm not a programmer this is my first programming language. Global variable was the problem, and I'll also check out if I can query the panels as suggested as that would be a bit cleaner, I'll post back if I can't get the panels working on my own. Here is the code that works with the global variable in a generic sense.
Replies
also good to understand variable declaration, which answers your problem with previous thread, you were declaring it twice.
you can read the state of the checker map by querying the UI like this:
then you can use the variable $checkerState to switch your if statements
https://help.autodesk.com/cloudhelp/2016/CHS/Maya-Tech-Docs/Commands/textureWindow.html
like this:
<br>
Here is the code that works with the global variable in a generic sense.