Please check out Materia Magica !

Member Discussions

terms



[Previous] [Next] [Post] [Reply] [Topics] [Summary] [Search]


1. 'look' code Tue Jun 29, 2004 [6:42 PM]
xael
Email not supplied
member since: Jun 3, 2004
Reply
Hey,

I'm in the process of coding my own 'look' code. Right now, i'm handling the part that will handle looking at other players. I know this is limiting (for instance, it doesn't put objects into considerations). Here's the code i have for it so far:
       D_MOBILE *xMob;

        if (arg[0] != '\0')
        {
                  for (xMob = dmobile_list; xMob; xMob = xMob->next)
                  {
                  if (xMob->socket->state != STATE_PLAYING && !strcmp(xMob->name, arg))
                        break;

                          printf_to_char(dMob, xMob->description);
                          printf_to_char(dMob, xMob->name);
                          return;
                  }
                  printf_to_char(dMob,'I do not see that here.\n\r');
                  return;
          }


You might not find the data structures fermiliar, just pretend dMob == ch and socket->state as d->connected (if you're used to ROM, that is). So, here's where I run into problems. On the MUD, if I type 'look simon' for instance, it will just give me the name of the first person in the d->connected list. Like this:

Simon@EverMud look simon

(null)Justin
Simon@EverMud look justin

(null)Justin
Simon@EverMud look fsdakfjvafwfv

(null)Justin
Simon@EverMud 

(null) is his ch->description, which currently isnt set, so that part makes sense. but the fact that it's always reading the first descriptor.. why is that happening? and is strcmp the command i should be using?

Thanks in advance for any help.


2. RE: 'look' code Tue Jun 29, 2004 [7:20 PM]
thyrr
Email not supplied
member since: Nov 21, 1999
In Reply To
Reply
You probably want it to look like:

for (xMob = dmobile_list; xMob; xMob = xMob->next)
{
    if (xMob->socket->state == STATE_PLAYING && !strcmp(xMob->name, arg))
    { // xMob is playing, and name matches
        printf_to_char(dMob, xMob->description);
        printf_to_char(dMob, xMob->name);
        return;
    }
}


Which I think would be cleaner overall. But I think what you were originally trying to do was:
if (xMob->socket->state != STATE_PLAYING || strcmp(xMob->name, arg))
    continue;


Which would skip the xMob if it were not in STATE_PLAYING, or if the name didn't match -- remember that strcmp returns 0 (false) if the name *matches*, some other number (true) if it doesn't match. And use OR instead of AND, because either condition should cause it to skip the xMob.


3. RE: 'look' code Tue Jun 29, 2004 [7:33 PM]
xael
Email not supplied
member since: Jun 3, 2004
In Reply To
Reply
Excellent! It was the strcmp that was tripping me up. Thanks for the help, works perfectly now!

Here's the full code, in case anyone else would benefit from something like this:

       D_MOBILE *xMob;

        if (arg[0] != '\0')
        {
                for (xMob = dmobile_list; xMob; xMob = xMob->next)
                {
                        if (xMob->socket->state == STATE_PLAYING && !strcmp(xMo$
                        {
                        printf_to_char(dMob, xMob->description);
                        printf_to_char(dMob, xMob->name);
                        return;
                        }

                }
                printf_to_char(dMob,'I do not see that here.\n\r');
                return;
        }


4. RE: 'look' code Tue Jun 29, 2004 [10:25 PM]
Scorpy
Email not supplied
member since: Jan 11, 2003
In Reply To
Reply
Nice to see another SocketMud user =)

Heres another idea for you to consider, to have the lookup in another return function, the same was Diku etc does I believe with get_char_world()?

D_MOBILE * getMobileByName( D_MOBILE * dMob, char * strName )
{
   D_MOBILE * xMob = NULL;

   if( strName[0] == '\0' ) {
      return NULL;
   }
   else if( !strcmp( strName, 'self' ) ) {
      return dMob;
   }
   else {
      for( xMob = dmobile_list; xMob != NULL; xMob = xMob->next ) {
         if( xMob->socket->state != STATE_PLAYING || !strcmp( xMob->name, strName ) ) continue;
         return xMob;
      }
   }
   return NULL;
}




Then inside a function just do:
if( ( xMob = getMobileByName( dMob, 'Bob' ) ) == NULL ) {
   printf_to_char( dMob, 'No such player\n\r' );
   return;
}
Imperium et Respectus
Scorpion-ice


5. RE: 'look' code Wed Jun 30, 2004 [6:42 PM]
xael
swbloom@gmail.com
member since: Jun 3, 2004
In Reply To
Reply
That med is a much more efficient way of doing it (also will help handle objects, mobs, etc). I just wrote a simple one, as we have yet to do anything with MOBs and objects.

I'd love to talk to you a bit about working with SocketMUD, some pitfalls / solutions you've encountered. If you want to give me a shout, it'd be greatly appreciated.

(Comment added by xael on Wed Jun 30 19:42:44 2004)

er. *med=method




[Previous] [Next] [Post] [Reply] [Topics] [Summary] [Search]