157
« on: February 26, 2008, 02:00:44 pm »
None of these things are overly hard or difficult to understand but just seem to be habits people pick up or simple things people don't think of immediately: Most of them lead to ambiguity or performance loss (lag) in the mud though, especially when the same small things are done repeatedly. They may seem insignificant, and truly, once or twice they are, 500 times across a zone and then in multiple zones, they do indeed add up.
Set vs. Eval
Wrong:
eval room %actor.room%
Correct:
set room %actor.room%
There's no reason to evaluate the ID of the room, it's a number, there's no parsing or math involved, by evaluating it only takes up more cpu time, it's also technically more to type.
Set vs. Nop
Wrong:
set %actor.gold(1000000)%
Correct:
nop %actor.gold(1000000)%
Again, they do the same thing except setting it creates an empty variable which is not intended and un-nneded, once again just un-needed cpu time. (I admit I'm guilty of this one myself semi-often but try to catch it.)
UID vs. Name
Wrong:
%send% %actor.name% This is a string of words.
Correct:
%send% %actor% This is a string of words.
%actor.name% is ambiguous, two mobs or players with the same name (meaning a mob and player with the same name, I'm aware two player's cant have the same name.) Also it takes un-needed cpu time to search the actor's char_data structure and retrieve their name when it doesn't need to. This is true for any time %actor% preceeds a DG-Command, ie. %teleport% %send% %echoaround% %goto% etc. On the other hand %actor.name% is needed when preceeding a mudcommand, such as give or look, or any social.
Also just something that seems odd that I find all over through most of the scripts. "endif" not sure where that really came from, but the if part is entirely superfluous and in fact it could endthegodforsakenscriptnow, and because of such all that is needed is end, which is also shorter and therefore faster to parse.
The purpose of Global Type Scripts:
This one isn't as common but is something I spotted the other day which made me quite certain that whoever wrote the script (not mentioning names) didn't know what the purpose of Global was.
set p %self.people%
if %p%
When those are the first two lines of a random global script attached to a room, all it being global does is kill cpu time. Random Triggers fire when a player and/or mob is in the room. Global Random Triggers fire regardless of whether someone is in the room or not. What that does is make it fire every time, but do nothing anyway if no one is in the room. Essentially, it's entirely wasteful and the Global Type on the script served no purpose butmaking the game run slower. A lot slower? No, but slower nonetheless.