Building & Scripting > Scripting Board

General Scripting Suggestions

(1/5) > >>

Fizban:
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:

--- Code: ---eval room %actor.room%
--- End code ---

Correct:

--- Code: ---set room %actor.room%
--- End code ---

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:

--- Code: ---set %actor.gold(1000000)%
--- End code ---

Correct:

--- Code: ---nop %actor.gold(1000000)%
--- End code ---

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:

--- Code: ---%send% %actor.name% This is a string of words.
--- End code ---

Correct:

--- Code: ---%send% %actor% This is a string of words.
--- End code ---

%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.


--- Code: ---set p %self.people%
if %p%
--- End code ---

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.

Mordecai:
Good stuff Fizban.

One more thing of RANDOM GLOBAL triggers.
Non GLOBAL triggers only fire when no one is in the ZONE rather then the ROOM.

If an Imm has nohassle ON then they are treated as not being in a zone, and normal RANDOM triggers may not fire if they don;t have GLOBAL when you are testing them.
However, if the trigger doesn't need to run when no one is there to see it, make sure you remove the GLOBAL from its trig type list.

Fizban:
Hmm, I wonder if TBA is different then, or, if me and umm..everyone else on TBA have had that part wrong for quite some time heh...because from their helpfile:


--- Quote ---TRIGEDIT-ROOM-GLOBAL TRIG-ROOM-GLOBAL

Not a trigger type by itself; used in conjunction with Random HELP
TRIGEDIT-ROOM-RANDOM and HELP TRIGEDIT-ROOM-TIME. While Random
and Time only trigger if players are in the same room, Global Random
and Global Time will trigger regardless.
 
Numeric Arg : not used.
Argument    : not used.

Variables:
%self% - the room.

Example: TSTAT 50

--- End quote ---

I read that originally and just took it at face value in assuming it was correct.

Mordecai:
I will just check the code. BRB!

Mordecai:

--- Code: ---if (IS_SET(SCRIPT_TYPES(sc), WTRIG_TIME) &&
                    (!is_empty(IN_ROOM(ch)->zone) ||
                     IS_SET(SCRIPT_TYPES(sc), WTRIG_GLOBAL)))
                time_mtrigger(ch);

--- End code ---

So on 4D it is if the ZONE is empty.

Let me just check the TBA code.

Navigation

[0] Message Index

[#] Next page

Go to full version