With the eg.globals.myvar = 100 statement I could set a global var.
But what if I would like to compare it against another value I have and I have not yet set the global var to any value?
in PHP there is the is_set() function. Anyway to do similar in python like eg.globals.myvar.exist = true?
Next question would be:
How can I make sure a defined and well set variable (or object in general) would be available next time I start EG? Do I need to "unload" into and "load" from a file?
Thanks!
jwka
Another Newbie Q: FIRST use of a global object & survival
Re: Another Newbie Q: FIRST use of a global object & survival
In terms of checking for variables, that depends on the variable's type. The most generic method is simply to use a try/except block:
eg.globals (which Bitmonster tells people never to use BTW) is a kind of strange type, like a modified dictionary. For dictionaries, you could use has_key, or the get method. So an example (again because eg.globals is strange) would be:
Saving variables between sessions uses eg.PersistentData. Check out this thread.
Brett
Code: Select all
try:
x = SomeClass.myVar
except:
pass #whatever you need to do if the variable doesn't exist
Code: Select all
eg.globals.__dict__.has_key("myvar")
Brett
Re: Another Newbie Q: FIRST use of a global object & survival
Thanks, Brett, will follow the links & try out your suggestions.
And ... you mentionned that bitmonster strongly recommends NOT to use eg.globals, what would be the alternative to that defining variables / objects to be used in multiple scripts?
rgds
jwka
And ... you mentionned that bitmonster strongly recommends NOT to use eg.globals, what would be the alternative to that defining variables / objects to be used in multiple scripts?
rgds
jwka
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Another Newbie Q: FIRST use of a global object & survival
That is utter nonsense, it's completely different:stottle wrote:eg.globals (which Bitmonster tells people never to use BTW) ...
PakoBitmonster wrote:No plugin should ever assign something to eg.globals or change anything in it. Never!
The eg.globals namespace is exclusive for the user's Python scripts and commands.
If your plugin wants to publish variables to the user, the preferred way is to implement getter actions, that simply return the value. This way the user can also easily see all informations your plugin can provide.
Re: Another Newbie Q: FIRST use of a global object & survival
Thanks Pako for making that clear.
I guess Brett might have mixed things up a bit.
jwka
I guess Brett might have mixed things up a bit.
jwka
Re: Another Newbie Q: FIRST use of a global object & survival
My bad, I do more plugin development than scripts, and I remembered the "Never!" of Bimonster's comment, not that it was specific to plugins. Sorry for the confusion.
Brett
Brett