[Closed] variable assigned to object
Hi all, quick question, I am assigning a variable to an object, so when I press a button it creates the object, I also have other buttons to hide this object and freeze it, the problem is when i exit the scene and load it again, the variable is not assigned to that object anymore so the freeze and hide button are not working anymore.
ex:
–create button
c= box ()
–hide button
c.ishidden = true
something like that its not exactly it but you get the idea… So my question is how do I tell max to store that variable in the scene…is there such a thing?
Thank you all
without going into details, you have several options for storing data in the scene, each with its pros and cons depending on your final goal:
- store it as parameter of a custom attribute on an object, or the rootnode of the scene
- scene file properties
- external file
- persistent scene globals
persistent global variables, exactly what I was looking for thanks you lo
for those who would like more details
http://www.kxcad.net/autodesk/Autodesk_MAXScript_Reference_9/Persistent_Global_Variables.htm
Here’s the problem with persistent global variables: they can get overwritten by other scripts. Say you tried to store a reference to your box:
c= box ()
c.ishidden = true
If c is a global variable, and c gets assigned a value by another script, then you’ve lost the reference to the box. So, if you never have to worry about another script running, then that approach is fine.
oh ok, Right now its only a tool for myself and the object assigned to the variable isnt an important part of the scene, its only a place holder, I constantly delete it and create it again sometimes instead of hiding it.
In the future I might distribute it to my coworkers tho so out of curiosity, what would be the workaround? giving it a super complicated name or one of the solution mentioned by lo?
If I were doing what you are, I wouldn’t use persistent globals. For ease of use and simpleness I would create your box with a unique name and refer to that name explicitly using your other scripts.
The rule is pretty much don’t use persistent globals.
-- Creation script
local c = Box name:"onlymybox"
-- Hide script
$onlymybox.isHidden = true
easy easy easy.
-Colin