PDA

View Full Version : Scripting Etiquette/Syntax


gsusfrk
06-25-2009, 12:27 PM
A very general question... When scripting, does it matter if I repeatedly make a call to a method/function instead of calling it once and assigning it to a variable? For example, is this:

void main()
{
AssignCommand(GetFirstPC(), ActionTakeItem("some_item", GetFirstPC()));
SendMessageToPC(GetFirstPC(), "Removed Item from inventory");
}

...the same as this?

void main()
{
object oPlayer = GetFirstPC();
AssignCommand(oPlayer, ActionTakeItem("some_item", oPlayer));
SendMessageToPC(oPlayer, "Removed Item from inventory");
}

Does either one have the advantage over the other? Other than readability, the second script doesn't seem to have any advantage over the first. I've coded with Java before, and in Java the two scripts would be exactly the same (unless the value of GetFirstPC() changes between its calls, which in this case, wouldn't happen). Do the same principles apply here?

One more question: what kind of rules should I follow when naming a script? Is there anything I should avoid, such as starting script names with numbers/certain characters, or the length of the name, etc.? Thanks a lot!