Stupid problem: unable to store variable data into another variable

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 10 October 2012   #1
Stupid problem: unable to store variable data into another variable

I'm working on my custom UV editor again and want to add functionality to store manipulation values for later use. The first procedure below is an example of a working one. $manipAmt is the variable holding the manipulation value (amount), $uvEntryField is the name of the input field, and $manipVarA is the variable I want to use for storage.

Code:
// Addition command (+0.01): $manipAmt += 0.01; floatField -e -v $manipAmt $uvEntryField; // Subtraction procedure (-0.01): global proc subtract001() { global float $manipAmt; global string $uvEntryField; if ($manipAmt >= 0.01) { $manipAmt -= 0.01; floatField -e -v $manipAmt $uvEntryField; } else { $manipAmt = 0; floatField -e -v 0.0 $uvEntryField; } } global proc readVarA() { global float $manipAmt; global string $uvEntryField; global float $manipVarA; floatField -e -v $manipVarA $uvEntryField; } global proc writeVarA() { global float $manipAmt; global float $manipVarA; $manipVarA = $manipAmt; }


There's obviously something I'm missing here because when I run the "read" procedure I don't get anything and the uvEntryField is just updated with a 0 (and $manipAmt remains). I'm suspecting that $manipVarA = $manipAmt isn't working - if it was then the value from the floatField would be stored there. And just to make sure, I also tried $manipVarA = $uvEntryField and that didn't work either.

Although the following is irrelevant, here are some buttons using my procedures:
Code:
iconTextButton -image1 "manipVal001.bmp" -command "$manipAmt += 0.01; floatField -e -v $manipAmt $uvEntryField;" -commandRepeatable true -label "Add/subtract 0.01" -annotation "Add/subtract 0.01" manipVal001; popupMenu -button 3 -p manipVal001 -postMenuCommand "subtract001()" manipVal001Popup; iconTextButton -image1 "manipVarA.bmp" -command "writeVarA()" -commandRepeatable true -label "Store/Read variable" -annotation "Store/Read variable" manipVarA; popupMenu -button 3 -p manipVarA -postMenuCommand "readVarA()" manipVarAPopup;

It's so frustrating because this error is there probably because of some newbie mistake. It's late and I've been scripting for far too long and I guess that's when you start losing focus.
__________________
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.

Last edited by DeadlyNightshade : 10 October 2012 at 10:04 PM.
 
Old 10 October 2012   #2
The problem appears to be that you are trying to read a global variable from a string that is getting evaluated without declaring the global in the string.. so basically it doesn't know what the global is.

just add the global to your string

-command "global string $uvEntryField;$manipAmt += 0.01; floatField -e -v $manipAmt $uvEntryField;"
__________________
blah blah blah
 
Old 10 October 2012   #3
Okay, I'll add "global" to all my $uvEntryField -declarations and see what happens. Thanks.
__________________
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.
 
Old 10 October 2012   #4
I checked my declarations and $uvEntryField is declared as a global everywhere in my script.
The only place it's not declared is in your example and in buttons like it - because it's not needed there. It's something else that doesn't work.

Procedure subtract001() in my original post works, but not the following two (variable storage procedures) so the issue is not with declarations it seems.
__________________
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.

Last edited by DeadlyNightshade : 10 October 2012 at 05:28 PM.
 
Old 10 October 2012   #5
Script now works and I don't even know what I did (if I even did anything).
__________________
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.
 
Old 10 October 2012   #6
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:56 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.