"buf" in old snippits

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 11 months ago #397 by Papaya Pete
"buf" in old snippits was created by Papaya Pete

Attachment eavesdrop.txt not found


Ok, taking a look at older code snippits, I'm noticing that a lot of them use something called "buf." For example, right now I'm trying to add in an eavesdrop snippit, and there is this line of code that I'm trying to figure out how to tackle.
if (!*buf) {
    send_to_char(ch, "In which direction would you like to eavesdrop?\r\n");
    return;
  }

I'm trying to figure out what to do with this, what I should be checking for, but seeing as I'm not especially familiar with the code it's making it a little difficult.

I'll add the entire snippit txt here so you can get the context. :)
Attachments:

Please Log in or Create an account to join the conversation.

More
5 years 11 months ago - 5 years 11 months ago #398 by bakarus
Replied by bakarus on topic "buf" in old snippits
Found this for you, should help.


Using a pointer we can directly access the value stored in the variable which it points to. To do this, we simply have to precede the pointer's identifier with an asterisk (*), which acts as dereference operator and that can be literally translated to "value pointed by".

Therefore, following with the values of the previous example, if we write:


beth = *ted;


(that we could read as: "beth equal to value pointed by ted") beth would take the value 25, since ted is 1776, and the value pointed by 1776 is 25.


You must clearly differentiate that the expression ted refers to the value 1776, while *ted (with an asterisk * preceding the identifier) refers to the value stored at address 1776, which in this case is 25. Notice the difference of including or not including the dereference operator (I have included an explanatory commentary of how each of these two expressions could be read):

beth = ted; // beth equal to ted ( 1776 )
beth = *ted; // beth equal to value pointed by ted ( 25 )


Notice the difference between the reference and dereference operators:
& is the reference operator and can be read as "address of"
* is the dereference operator and can be read as "value pointed by"
Last edit: 5 years 11 months ago by bakarus.

Please Log in or Create an account to join the conversation.

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 11 months ago #399 by Papaya Pete
Replied by Papaya Pete on topic "buf" in old snippits
Hmm it does somewhat, but what I'm trying to figure out is what *buf is trying to point to in the first place. Also, lots of older snippits use it elsewhere in a different way.

Example (just an example, not from any code):
sprintf(buf, "You look around but fail to find anything of interest nearby", ch);

If you don't remove them then there are compiling errors since "buf" is not defined. So I'm trying to figure out what it is used for so I have a better idea on what to replace *buf with. I know what it is checking for: a direction that the player wants to eavesdrop on. So, if he doesn't input anything then it will give that message. That's the snag I've hit, and it's due to my lack of coding experience in general, I bet. :P

Thanks for the info though. :)

Please Log in or Create an account to join the conversation.

More
5 years 11 months ago #400 by Liko
Replied by Liko on topic "buf" in old snippits

Papaya Pete wrote: Hmm it does somewhat, but what I'm trying to figure out is what *buf is trying to point to in the first place. Also, lots of older snippits use it elsewhere in a different way.

Example (just an example, not from any code):
sprintf(buf, "You look around but fail to find anything of interest nearby", ch);

If you don't remove them then there are compiling errors since "buf" is not defined. So I'm trying to figure out what it is used for so I have a better idea on what to replace *buf with. I know what it is checking for: a direction that the player wants to eavesdrop on. So, if he doesn't input anything then it will give that message. That's the snag I've hit, and it's due to my lack of coding experience in general, I bet. :P

Thanks for the info though. :)


define like this ;
char buf[MAX_STRING_LENGTH];

DragonBall: Tournament (1.2.0)
Owner/Developer

Please Log in or Create an account to join the conversation.

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 11 months ago #401 by Papaya Pete
Replied by Papaya Pete on topic "buf" in old snippits
Hmmm that seemed to resolve that compiling error. Here is another one that's got me stumped (going to really need to study up on pointers!):

Now in structs.h, the snippit says to put this into the char_data struct...
  struct char_data *next_listener;
  sh_int listening_to;

Now I'll mark ** where the compiler is having problems. This is in act.other.c.
ACMD(do_eavesdrop) {
  int dir;
  int pchance;
  char buf[MAX_STRING_LENGTH];
  one_argument(argument, buf);

  if (!*buf) {
    send_to_char(ch, "In which direction would you like to eavesdrop?\r\n");
    return;
  }
  if ((dir = search_block(buf, dirs, FALSE)) < 0) {
    send_to_char(ch, "Which directions is that?\r\n");
    return;
  }
  if (!GET_SKILL(ch, SKILL_EAVESDROP)) {
    send_to_char(ch, "You try to eavesdrop on that room, but fail.\r\n");
    return;
  }

  pchance = rand_number(1, 101);
  if (pchance > GET_SKILL(ch, SKILL_EAVESDROP)) {
    send_to_char(ch, "You try to listen in on the next room, but you can't make out anything.\r\n");
    return;
  }
    else {
      if (EXIT(ch, dir)) {
        if (IS_SET(EXIT(ch, dir)->exit_info, EX_CLOSED) && EXIT(ch, dir)->keyword) {
          sprintf("The %s is closed.\r\n", fname(EXIT(ch, dir)->keyword));
          //send_to_char(buf, ch);
         } else {
            ch->next_listener = world[EXIT(ch, dir)->to_room].listening;  //******
            world[EXIT(ch, dir)->to_room].listening = ch;
            ch->listening_to = EXIT(ch, dir)->to_room;   //******
            //send_to_char(OK, ch);
    }
  } else
    send_to_char(ch, "There is not a room there...\r\n");
    }
}

Here is the error message it's giving me.
act.other.c: In function ‘do_eavesdrop’:
act.other.c:134:15: error: ‘struct char_data’ has no member named ‘next_listener’
act.other.c:136:15: error: ‘struct char_data’ has no member named ‘listening_to’

Please Log in or Create an account to join the conversation.

  • Vatiken
  • Vatiken's Avatar
  • Offline
  • Administrator
  • Administrator
  • tbaMUD Programmer
More
5 years 11 months ago #403 by Vatiken
Replied by Vatiken on topic "buf" in old snippits
Make sure that *next_listener and listening_to are in the correct structure and make sure to do a clean compile.

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 11 months ago #418 by Papaya Pete
Replied by Papaya Pete on topic "buf" in old snippits
Yeah, that did it! I had accidentally put it under "char_special_data" instead of "char_data".

So here is another error that's coming up, in interpreter.c. Here is the error message...
interpreter.c: In function ‘command_interpreter’:
interpreter.c:492:5: error: ‘temp’ undeclared (first use in this function)
interpreter.c:492:5: note: each undeclared identifier is reported only once for each function it appears in
interpreter.c:493:22: warning: assignment makes integer from pointer without a cast

So here is the actual lines of code with some of what is around it.
REMOVE_BIT_AR(AFF_FLAGS(ch), AFF_HIDE);

  // Eavesdrop
    if (ch->listening_to) {
    REMOVE_FROM_LIST(ch, world[ch->listening_to].listening, next_listener);
    ch->listening_to = NULL;
  }
  // End Eavesdrop

  /* just drop to next line for hitting CR */
  skip_spaces(&argument);
  if (!*argument)
    return;

  /* special case to handle one-character, non-alphanumeric commands; requested
   * by many people so "'hi" or ";godnet test" is possible. Patch sent by Eric
   * Green and Stefan Wasilewski. */
  if (!isalpha(*argument)) {
    arg[0] = argument[0];
    arg[1] = '\0';
    line = argument + 1;
  } else
    line = any_one_arg(argument, arg);

So the instructions for the snippit mentioned putting in that small bit after where the HIDE affect is removed (just from what I remember, I don't have the instructions open in front of me).

I'll take another look, I've been unable to reply due to being so busy. Thank you so much for your help!

Please Log in or Create an account to join the conversation.

  • Vatiken
  • Vatiken's Avatar
  • Offline
  • Administrator
  • Administrator
  • tbaMUD Programmer
More
5 years 11 months ago #419 by Vatiken
Replied by Vatiken on topic "buf" in old snippits
"REMOVE_FROM_LIST" uses the variable "temp" within it's definition. The variable should be the same as the first variable ("ch") sent in "REMOVE_FROM_LIST".

You should be able to solve your first warning then by entering "struct char_data *temp;" at the beginning of the function.

The second issue is because you are attempting to set "sh_int listening_to" to "NULL", which is invalid because "NULL" sets a pointer to 0x0. As I'm not sure what "listening_to" is actually for, I can't really offer up any accurate advice for what it should then be set to.

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 11 months ago #422 by Papaya Pete
Replied by Papaya Pete on topic "buf" in old snippits
That seemed to work, and did a little playing around with it (changed NULL to 0 just to see what will happen; I have the feeling it's going to be listening to a location constantly or something, heh).

Now in comm.c there is an issue with SEND_TO_Q, as it's saying that this is undefined. Here's the snippit in comm.c, I left in the old send_to_room so that it's more easily compared.
/* New Eavesdrop send_to_room */
void send_to_room(room_rnum room, const char *messg, ...)
{
  struct char_data *i;

  if (messg) {
    for (i = world[room].people; i; i = i->next_in_room)
      if (i->desc)
        SEND_TO_Q(messg, i->desc);
    for (i = world[room].listening; i; i = i->next_listener)
      if (i->desc) {
/*  the ------'s are used to differentiate eavesdropped stuff from
 *  the stuff that is happening in the same room as the char..
 *  looks like:
 *  -------
 *  john dropped a sword
 *  ------
 */
        sprintf("----------\r\n%s----------\r\n", messg);
        SEND_TO_Q(i->desc);
      }
  }
}
/* This is the old send_to_room code, before eavesdrop
void send_to_room(room_rnum room, const char *messg, ...)
{
  struct char_data *i;
  va_list args;

  if (messg == NULL)
    return;

  for (i = world[room].people; i; i = i->next_in_room) {
    if (!i->desc)
      continue;

    va_start(args, messg);
    vwrite_to_output(i->desc, messg, args);
    va_end(args);
  }
} */

Not sure what SEND_TO_Q is used for, do you happen to remember what it does?

Please Log in or Create an account to join the conversation.

  • Vatiken
  • Vatiken's Avatar
  • Offline
  • Administrator
  • Administrator
  • tbaMUD Programmer
More
5 years 11 months ago #423 by Vatiken
Replied by Vatiken on topic "buf" in old snippits
Pretty sure it serves the same purpose as "write_to_output()", so just go:

write_to_output(i->desc, messg);

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 11 months ago #424 by Papaya Pete
Replied by Papaya Pete on topic "buf" in old snippits
So that worked out, it compiled and ran. However, when trying to eavesdrop on the next room nothing was sent to the one eavesdropping. I took a brief look around and saw that someone had the same problem. So they tried adding to act() in comm.c:

At the top of act():
struct char_data *evasdropper;

At the bottom of act():
for (; to; to = to->next_in_room) {
    if (!SENDOK(to) || (to == ch))
      continue;
    if (hide_invisible && ch && !CAN_SEE(to, ch))
      continue;
    if (type != TO_ROOM && to == vict_obj)
      continue;
    perform_act(str, ch, obj, vict_obj, to);
  }

/* ADD EAVESDROP STUFF HERE: */

  /* Send action to any eavesdroppers in neighboring rooms */
  for (eavesdropper = world[ch->in_room].listening; eavesdropper;
       eavesdropper = eavesdropper->next_listener) {
    if (eavesdropper->desc) {
      /*  the ------'s are used to differentiate eavesdropped stuff from
       *  the stuff that is happening in the same room as the char..
       *  looks like:
       *  -------
       *  john dropped a sword
       *  ------
       */
      SEND_TO_Q("----------\r\n", eavesdropper->desc);
      perform_act(str, ch, obj, vict_obj, eavesdropper);
      SEND_TO_Q("----------\r\n", eavesdropper->desc);
    }
  }

So I tried using write_to_output instead of SEND_TO_Q. Didn't quite work out.
comm.c: In function ‘act’:
comm.c:2695:7: warning: passing argument 1 of ‘write_to_output’ from incompatible pointer type
comm.c:1258:8: note: expected ‘struct descriptor_data *’ but argument is of type ‘char *’
comm.c:2695:7: warning: passing argument 2 of ‘write_to_output’ from incompatible pointer type
comm.c:1258:8: note: expected ‘const char *’ but argument is of type ‘struct descriptor_data *’
comm.c:2697:7: warning: passing argument 1 of ‘write_to_output’ from incompatible pointer type
comm.c:1258:8: note: expected ‘struct descriptor_data *’ but argument is of type ‘char *’
comm.c:2697:7: warning: passing argument 2 of ‘write_to_output’ from incompatible pointer type
comm.c:1258:8: note: expected ‘const char *’ but argument is of type ‘struct descriptor_data *’

Please Log in or Create an account to join the conversation.

  • Vatiken
  • Vatiken's Avatar
  • Offline
  • Administrator
  • Administrator
  • tbaMUD Programmer
More
5 years 11 months ago #429 by Vatiken
Replied by Vatiken on topic "buf" in old snippits
Your write_to_output() arguments are reversed...

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 11 months ago #432 by Papaya Pete
Replied by Papaya Pete on topic "buf" in old snippits
-_- Good grief. All I can say about that.

Thank you so much for your patience! Works perfectly now. :)

Please Log in or Create an account to join the conversation.

  • Papaya Pete
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
More
5 years 2 months ago - 5 years 2 months ago #2059 by Papaya Pete
Replied by Papaya Pete on topic "buf" in old snippits
It turns out all I needed was to walk away from it for a day. Fixed the issue I was having, and within the hour I'll upload an updated version of eavesdrop.

Thanks again for the help! :)
Last edit: 5 years 2 months ago by Papaya Pete. Reason: Fixed the issue that caused me to post.

Please Log in or Create an account to join the conversation.

Time to create page: 2.491 seconds