PDA

View Full Version : Delete Globals?


Gabester
10-18-2005, 02:20 AM
Hey all,

Is there a way to delete global variables? It would make sense. Once you've finished executing your entire script, just call on a code to delete them. This way it would save you the headache of still having them in the scene.

Anyone know of an answer?

NolanSW
10-18-2005, 06:18 AM
Simple...close Maya. You can not delete a global variables. Best not to use them at all.There are simple tricks to retrieve data without using globals. Invisible controls in a window or create attributtes on an empty node, set and get data and then delete when your done.

Sean

Gabester
10-20-2005, 01:01 AM
Hi Nolan.

I thought you can't delete them, but better to be sure.

Could you give me a quick example to how I would add data to a node and then retrieve it? I really don't have the faintest idea. I gather that you create a locator or something of the sort. Then create an attribute.

What If I want to add the name of an object to a string variable on this node?

It would be really helpful.

Thanks again.

NolanSW
10-20-2005, 02:41 AM
So here is just a quick example:

string $sphereName[] = `sphere`;
spaceLocator -p 0 0 0 -n temp;
addAttr -ln saveThis -dataType "string";
setAttr "temp.saveThis" -type "string" $sphereName[0];

string $retrieveString = `getAttr "temp.saveThis"`;
print $retrieveString;
delete temp;


Simple.
Created a sphere and a locator
Created a string attribute for the locator called temp.saveThis
Set the string to be the name of the sphere
Retrieved the name
Deleted the locator

Now, if you have a UI you can create a textbox that is invisible, put data in that and retrieve it from another function without using a global variable. I do that quite often. If it needs to be numeric than I just create a floatField or an intField control. But if you are not using a UI then the first example works well for that.

Hope that helps answer your question.

Sean

Gabester
10-22-2005, 12:20 AM
Absoulutely. You are the man!

CGTalk Moderation
10-22-2005, 12:20 AM
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.