globals

Post new topic   Reply to topic Scripting Questions View previous topic :: View next topic  
Author Message
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Sun Jan 13, 2008 3:24 pm    Post subject: globals Reply with quote

the question is short and sweet:

what is difference between just declaring a global inside a script and declaring global in the field at top of script editor? Confused
_________________
Cheiron
______________________________
"Any scientist with respect for himself should start
the day by rejecting his own pet hypotheses".
(Konrad Lorenz)

"Wir müssen wissen
Wir werden wissen"
(David Hilbert)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Mon Jan 14, 2008 12:43 am    Post subject: Reply with quote

The short answer is scope. Yeah real helpful I know.

From Learning Python (O'Reilly publishers) page 104

The global statement is the only thing that's anything like a declaration in Python. It tells Python that a function plans to change global names -- names that live in the enclosing module's scope (namespace). We've talked about global in passing already; as a summary:

* global means "a name at the top-level of a module file."
* global names must be declared only if they are assigned in a function.
* global names may be referenced in a function without being declared.

Also there are several documents at http://www.python.org/doc/ that may be helpful.
Back to top
View user's profile Send private message Visit poster's website
Bri



Joined: 06 Aug 2004
Posts: 237
Location: Palm Springs, CA

PostPosted: Mon Jan 14, 2008 3:53 am    Post subject: Hmmmm Reply with quote

always thought the global statement is used to allow access to a global variable, not to declare one.
_________________
RL..now with 100% less lag!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Studio 12
Site Admin


Joined: 04 Aug 2004
Posts: 67

PostPosted: Mon Jan 14, 2008 9:42 am    Post subject: Reply with quote

The other haft of the answer is.

I believe the global field at the top of the script editor is for delclaring a script "global" for the whole server. You have to enter the room which it resides in for it to load.
_________________
Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic.
Back to top
View user's profile Send private message
Scotsman
Site Admin


Joined: 03 Aug 2004
Posts: 705
Location: MadWolf Software

PostPosted: Mon Jan 14, 2008 3:39 pm    Post subject: Reply with quote

So did I Bri, but apparently I was mistaken. Going to have to play with it a little bit now that had to go look up the info for Cheiron.

That's correct Studio, that field allows you to declare a module name to detach the script into so it is not purged from memory when you leave the room.
Back to top
View user's profile Send private message Visit poster's website
Cheiron



Joined: 21 Apr 2005
Posts: 388
Location: Copenhagen, Denmark

PostPosted: Tue Jan 15, 2008 12:24 am    Post subject: Reply with quote

Scotsman wrote:

That's correct Studio, that field allows you to declare a module name to detach the script into so it is not purged from memory when you leave the room.


AHA !.... now we are getting somewhere.

well...back to reading about python..... Rolling Eyes

I will be back...... lol
_________________
Cheiron
______________________________
"Any scientist with respect for himself should start
the day by rejecting his own pet hypotheses".
(Konrad Lorenz)

"Wir müssen wissen
Wir werden wissen"
(David Hilbert)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic All times are GMT - 6 Hours
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum