Re: [SCRIPT] DG Scripts

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 07/31/00


Thomas Arp wrote:
>
> From: "Torgny Bjers" <tb@sbbs.se>
> Subject: Re: [CIRCLE] [SCRIPT] DG Scripts
>
> <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 "".

> 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% %self.name% actually puts the text "%self.name%" into the var %test%

Ummm, wrong again, on two counts.  %self.name% 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 %self.name%.  So if %self.name% 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% %self.name% puts the name referred to by the field into the var %test2%

Wrong again, see above for the reason why.

> Your problems with while() comes from an assignment:
>
> > set nextplr %nextplr.next_in_room%
>
And, once again, wrong.  This is quite the correct way to make the
assignment.

> this will then be checked in the next loop:
> %nextplr% (= "%nextplr.next_in_room%") =! ""

What the heck is this mess?  No one ever posted this garbage up yet.

> which is always true.

I'm not even gonna comment as to what the above mess will evaluate to.

Perhaps you meant this line...

while ("%nextptr%" != "")

That line works quite well and what it means in layman's terms is...

while the variable nextptr is not an empty string.

> I'm just surprised you got it to work on more than one player in a room..

It worked because it was correct.

> If you use
>
> eval nextplr %nextplr.next_in_room%

eval will cause DG Scripts to try to interpret what is in
%nextplr.next_in_room% as an equation (you know, the 1+1=2 type of
equation).  I'm not exactly sure if it would work or not.  I suppose I
could go out of my way to test it, but why should I bother if (1) I know
that set works perfectly fine, and (2) well, if you didn't test my code,
why should I test yours?

>
> instead, no problems should arise, and you should be able to skip the check for "The void"

For once we are in agreement, the check for "The Void" is quite
unnecessary as I pointed out earlier.

<snip out the part where I was praised for having code that works>
>
> The following script works too.

And you tested it, right?

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

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

> * Do whatever necessary - this could be wreward, too..
>   %echoaround% %person% The medics see to %person.name%s wounds.
>   %send% %person% You are cared for by the medics.
>   dg_cast 'cure light' %person.name%
>   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.

A side note as to the legitimate difference between set and eval...

eval test 1+1
%test% will return "2"

set test 1+1
eval test2 %test%
%test% will return "1+1"
%test2% will return "2"

eval test 1+1
set test2 %test%
%test will return "2"
%test2% will return "2"

Regards, Peter


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



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