Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Wed Apr 30, 2008 7:28 pm   

Local Variables
 
I understand that these are faster
Is there a place that they are stored so i can view them?
Is it worth going through all my scripts to use these vs DBs or Vars?
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Apr 30, 2008 7:51 pm   
 
They are not stored anywhere. They are essentially temporary variables, used only for that script. Put to real life examples:

A fork would be a stored variable. You use it every time you eat, then you store it for later use.

A match is a one time use - you know where to get it, you use it, then you toss it. Less clutter.

Horrible examples, I know, but that's the way that I look at them. :P

Charneus
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Wed Apr 30, 2008 7:51 pm   
 
Actually, if you go through your variables and set them all to use default then your normal variables will be just as fast.
I would not suggest setting your database variables to use default however.

A local variable is by design in memory only for the duration of the script.
That is what makes it a LOCAL variable. Because of this you cannot view it in the package editor.

The main strength of a local variable is that you can create a script with many variables within it and you do not have to litter up your class with variables that are not used between scripts.
Because when the script is finished the variable goes away.
This also means that your packages are much smaller than they would have been otherwise.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Apr 30, 2008 10:21 pm   
 
Arminas: While setting "Use Default" to true will make normal variables faster, they still won't be as fast as local variables. Local variables are *very* fast.

To expand upon what Arminas was saying, setting "Use Default" to true means that changes to your variable are not stored between sessions (because the variable gets initialized to it's default value when the session is loaded). So do not set "Use Default" for variables that you want saved in your session.
Reply with quote
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Thu May 01, 2008 8:06 am   
 
Ahh, ok, That makes it clearer.
So for mob targetting and such local variables are the way to go.
but for Tracking and such NOT the way to go.. Thanks
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu May 01, 2008 10:07 am   
 
Not necessarily, harley. Local variables only exist within the currently-running script. That's why they're called local (as opposed to global) variables - global variables are accessible from anything, but local variables only exist where they're created. An illustrative example:

#alias one {$something="yes"}
#alias two {#say $something}

Two will fail with an invalid local variable error because the variable was defined inside the "one" alias and destroyed when that alias finished. So it's useful for those times when you'd be using a variable (usually named temp or something) to hold a value only during that alias. Also, see the help.

The only difference between "use default" and normal variables is that their values are never saved to the disc, which makes it slightly faster if you use them. But obviously their values will be lost when you exit - you can store stuff you're updating often like your HP values and stuff in them, though.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net