Re: [SCRIPT] DG Scripts

From: Thomas Arp (
Date: 07/31/00

From: "Peter Ajamian" <>
Subject: Re: [CIRCLE] [SCRIPT] DG Scripts

> Thomas Arp wrote:
> >
> > From: "Torgny Bjers" <>
> >
> > <snip of script>
> >
> > > The reason to why the while.. doesn't work like it should in this case is
> > > because %nextplr.next_in_room% doesn't return "" when it is done, does it?
> > > It returns a carriage return, eh? So it will NEVER be "" will it?
> > > Therefore, infinite loop (my oh my, does it eat CPU when writing errors to
> > > the logfile! :])
> >
> > Actully %nextplr.next_in_room% DOES return "" if there aren't any more people in the room, as you can see here (from dg_scripts.c):
> >
> >       else if (!str_cmp(field, "next_in_room")) {
> >         if (c->next_in_room)
> >           sprintf(str,"%c%ld",UID_CHAR, GET_ID(c->next_in_room));
> >         else strcpy(str,"");
> >       }
> Actually, %nextplr.next_in_room% returns nothing, an empty string, as in
> the above example.  "%nextptr.netxt_in_room%" returns "".

Which is what I wrote..

> > Your problems might be caused by the use of 'set' instead of 'eval'. Set only assigns the text, whereas eval substitutes (or calulates or whatever you want to call it) right away , ie. :
> > set %test% actually puts the text "" into the var %test%
> Ummm, wrong again, on two counts. is substituted out before
> the set command is ever called.  Also, by putting %test% as the first
> arg, you will set a variable with the name of whatever is in test eaqual
> to whatever is in  So if is fred, and %test% is
> jane the set command actually sees this
> set jane fred
> and you end up with a variable named "jane" with the text "fred" in it
> (both without the quotes).
> > eval %test2% puts the name referred to by the field into the var %test2%
> Wrong again, see above for the reason why.

Really? - maybe I phrased it wrongly.. I actually meant the thing you're saying  :P
The line I was meaning to write was :
eval test2


> <snip out the part where I was praised for having code that works>
> >
> > The following script works too.
> And you tested it, right?
Of course.

> > * init the loop
> > eval person %self.people%
> eval is overkill and requires more overhead where set will do the job.
> >
> > while (%person%)
> I'm not ceartain, but while MAY complain if %person% is an empty string
> in this case.  Also, it will fail if %person% is 0 (as opposed to an
> empty string), to specifically check for an empty string the safe way to
> do it is...

It won't. First off, %person% cannot be 0, since it's a UID. It's either an empty string "", or a number with a strange char ('\x1b') in front. The notation of FALSE in dg_scripts is either 0 or an empty string, making the above example work. ie. if %person% is an empty string, the evaluation will be
while ()
which would skip the loop instantly.

> while ("%person%" != "")

Waste of characters, if you ask me.. Well, guess I make up for it in evals instead of sets :}

> > * Do whatever necessary - this could be wreward, too..
> >   %echoaround% %person% The medics see to wounds.
> >   %send% %person% You are cared for by the medics.
> >   dg_cast 'cure light'
> >   wait 1
> >   eval person %person.next_in_room%
> again, eval...
> > done
> Please, if you're going to criticize my code here, at least have the
> decency to know what you're talking about and to check up on it first.

My criticism was intended as constructive and instructive. I'm glad you corrected some of the errors I made, because things don't always come out in writing as I intend them to. I will however continue to use eval instead of set whenever I feel like it - and wherever it fits the code.

But I guess I'm wrong and you're right.. There are no hard feelings from my side about that.


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 04/10/01 PDT