----- Original Message ----- From: Del <caminturn@earthlink.net> To: <CIRCLE@post.queensu.ca> Sent: Monday, June 28, 1999 1:39 PM Subject: [?] Difference between d->character and ch *snip* > at top of file: > #include "conf.h" > #include "sysdep.h" > #include "structs.h" > #include "comm.h" > #include "utils.h" > #include "olc.h" > #include "handler.h" > #include "interpreter.h" > #include "db.h" > ACMD is a macro, that takes it's parameter and is interpreted as follows: ACMD(do_xxx) void do_xxx(struct char_data *ch, char *argument, int cmd, int subcmd) Therefore, do_edit is a void function that receives a char_data pointer, an argument, and cmd and subcmd numbers. > ACMD(do_edit) > { At this point, d points to nothing in particular[1]. You'll also reference "number" below, which isn't declared here. Declare it. > struct descriptor_data *d; > > /* a few checks like */ > At this point in the code, ch exists because the command_interpreter() passes it as an argument to this function, do_edit(). > if (IS_NPC(ch)) > return; > I'm 99% sure that what you have below won't work in many (all) cases. You never put anything in buf1, first of all (the arguments to a command are passed in (char *) argument). In other words: if (!*argument) { send_to_char(HOW_TO_USE_DO_EDIT_STRING, ch); return; } /* relatively sure that arg1 is a global character array */ argument = one_argument(argument, arg1); /* you need to make sure they type proper arguments. Error handling in a MUD is a necessity. */ if (!is_number(arg1)) { send_to_char(HOW_TO_USE_DO_EDIT_STRING, ch); return; } > /* pull the number argument from the input */ > number = atoi(buf1); Change that to: number = atoi(arg1); > > /* following along zedit */ > Alright, you've never bothered to make d point to anything. In the stock CircleMUD code, `d' is typically used to refer to someones descriptor. One often can refer to a character by their descriptor, due to the link between the descriptor and the character, looked at via `d->character'. This can be invalid at various points, especially prior to actually logging into the MUD. Anyway, you're just mimicking code found elsewhere in the MUD at this point. `d' has to be something. If you want it to reference the character's descriptor, change at the top: struct descriptor_data *d; to: struct descriptor_data *d = ch->desc; You see, there's also a reverse link between a character and their descriptor. You can ignore `d' in this whole process, simply by passing `ch->desc' as an argument to this function. > edit_setup(d, number); becomes: edit_setup(ch->desc, number); > send_to_char("WE GET TO HERE FINE IF send_to_char in edit_setup IS NOT IN THE CODE", ch); I hope you understand why, at this point. > / * removed for testing > STATE(d) = CON_EDIT; > */ > > return; > > } > > void edit_setup(struct descriptor_data *d, int number) > { > > /* run a few checks that appear to work fine (messages inserted works fine > above) */ > You have no `ch' in this function! That error when compiling should tell you this. You passed a descriptor to this function. Use it, if you wanted it in the first place. > send_to_char("MUD WILL NOT COMPILE WITH 'ch' TO IN THIS LINE " > "ch undeclared (first use of this function)", ch); would work (if you follwed the instruction above) as: send_to_char(BLAH_STUFF_ABOVE, d->character); The line below won't work simply because you weren't passing a valid `struct descriptor_data *d'. Read above. > send_to_char("MUD WILL CRASH IF I USE THIS LINE, SEE ERROR AT TOP", > d->character); > > /* this follows similarly to zedit, cept zedit_setup has no send_to_char */ > /* only the call to zedit_disp_menu(d) in which there are , ch)'s */ > /* so this is why I am confused, as to why the different d->character and ch > */ > } In other words, in their typical usage throughout CircleMUD, `ch' and `d->character' refer to the same thing: a pointer to a char_data structure. In all cases where `d' is `ch's descriptor, and `ch' is the char_data structure associated with the descriptor: ch->desc == d; d->character == ch; I don't know how else to say it. If you still have problems, maybe somebody can rewrite this in better terms. -k. +------------------------------------------------------------+ | 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 : 12/15/00 PST