Leurnid wrote...
Almost every scripting tutorial begins by teaching best practices in regard to defining variables at the beginning and using variables instead of calling for data every time you need it (defining and using oSelf throughout a script instead of OBJECT_SELF, for instance).
If you have a tutorial that is telling you that it is a better practice to use oSelf in place of OBJECT_SELF, In all places. You have a bad tutorial. Or at least a tutorial that is teaching something that is not always the best practice. The fact of the matter is that best practice is not globally unique, What is a best practice for one person may not be the best practice for another. We will use your OBJECT_SELF as an example for this. It is in fact faster and better to use OBJECT_SELF in a script. OBJECT_SELF Retrives the data faster then getting the same data being priviously stored in into a Var named oSelf. The reason for this is quite simple OBJECT_SELF is the current object so it's location in memory is already loaded into the ESI regester on the CPU. There are time however when using OBJECT_SELF can get a beginer scripter into trouble, because OBJECT_SELF will always refferance the object that the code is currently running on. With the use of AssignCommand that object is not always the same as the object the script is running on. For a scripter who has an understanding of how OBJECT_SELF reacts in given scripts, It is a better practice to use OBJECT_SELF then the var oSelf. If the scripter is a biginer and does not have an understanding in the way it reacts, he is better off always use oSelf except in the cases where he has learned that OBJECT_SELF is needed for the correct results.
In fact now that I am thinking about it, Defining all the Vars at the begining of the script is also subjective. There are times where it is not the best practice.
I wish those tuts had included more on when, where, and how to predefine local vars.
It's all academic of course.
When: Anytime you need to pass information into a script from another script.
Where: normally for me it is from within a script that I set Iocal Vars. I seldom set them in the toolset, But I that is an option also.
How: With the Toolset or the Scripting functions.
The LocalVars are nothing more then variables that have ben attached to an object. Being attached to an object that have a scope(Life Span) equal to the life span of the object. This alows you to create vars that have a larger scope then the vars used in a script. So basicly every thing you learn about variables that are local to you script, Also apply to the things we call LocalVars that are nothing more then variables that are Local to an Object.