Hey all, I wrote a function to replace the stock circle prompt one. I added variables(char * and char[256]) in the player data and file structure, then changed do_display to allow the player to enter a series of letters, numbers, and symbols in order to create their own prompt(i.e. $h/$HHP or $%h%H would yield 500/500HP or 100%H). The initial symbol that would start a search for recognized variables is the '$'. I ran into a problem when I re-compiled and connected. Foof. Game crashes. I threw in a couple log statements, but I can't give you any GDB output because..well.. I don't run Linux(ducks). However, I can tell you that the program seems to be dying in the last use of strlen() in the function(line reading sprintf(prompt + strlen(prompt), "> "); ) just before return(prompt);. I believe that this crash is being caused by my lack of knowledge about indirections and how to use them, which we haven't covered in the C++ class I am currently taking. Here is the log output: Jan 20 21:25:25 :: New connection. Waking up. Jan 20 21:25:25 :: make_prompt called, desc data: connected = 2 has_prompt = 1 Jan 20 21:25:25 :: if d->connected is true [crash] The entire MUD is stock, except for this modification. If anyone can spot any problems with the following code(of which I'm sure there are many), I'd appreciate a response detailing whats wrong, and if its not too much to ask, a possible fix for it or suggestions. Thanks in advance! char *make_prompt(struct descriptor_data *d) { char *pprompt;// prompt string w/vars char *prompt; // actual prompt string char c[3]; struct char_data *enemy = NULL, *tank = NULL, *ch = NULL; int percent, i, var, p = 0, len; log("make_prompt called, desc data: connected = %d has_prompt = %d", d->connected, d->has_prompt); if(!d->character){ if(d->connected) log("if d->connected is true"); else log("false"); /* Note, prompt is truncated at MAX_PROMPT_LENGTH chars (structs.h ) */ if (d->str) strcpy(prompt, "] "); else if (d->showstr_count) sprintf(prompt, "\r\n[ Return to continue, (q)uit, (r)efresh, (b)ack, or page number (%d/%d) ]", d->showstr_page, d->showstr_count); else if (!d->connected) { log("!d->connected"); *prompt = '\0'; log("assigning ch"); ch = d->character; log("ch assigned"); enemy = FIGHTING(ch); pprompt = GET_PROMPT(d->character); skip_spaces(&pprompt); len = strlen(pprompt); log(len); for(i = 0; i < len; i++){ c[0] = pprompt[i]; if(c[0] == '$'){ c[1] = pprompt[i++]; var = 1; } else sprintf(prompt + strlen(prompt), "%c", c[0]); if(c[1] == '%'){ c[2] = pprompt[i++]; p = 1; } else sprintf(prompt + strlen(prompt), "%c", c[1]); if(c[0] == '$'){ if(p){ switch(c[2]){ case 'h': case 'H': percent = ((float) (GET_HIT(ch) / GET_MAX_HIT(ch))*100); sprintf(prompt + strlen(prompt), "%d%%", percent); break; case 'm': case 'M': percent = ((float) (GET_MANA(ch) / GET_MAX_MANA(ch))*100); sprintf(prompt + strlen(prompt), "%d%%", percent); break; case 'v': case 'V': percent = ((float) (GET_MOVE(ch) / GET_MAX_MOVE(ch))*100); sprintf(prompt + strlen(prompt), "%d%%", percent); break; case 'x': case 'X': percent = ((float) (GET_EXP(ch) / (level_exp(GET_CLASS(ch), (GET_LEVEL(ch)+1))*100))); sprintf(prompt + strlen(prompt), "%d%%", percent); break; } // switch(c[2] } // if(p) switch(c[1]){ case 'h': // curr. health sprintf(prompt + strlen(prompt), "%d", GET_HIT(ch)); break; case 'H': // max health sprintf(prompt + strlen(prompt), "%d", GET_MAX_HIT(ch)); break; case 'm': // curr. mana sprintf(prompt + strlen(prompt), "%d", GET_MANA(ch)); break; case 'M': // max mana sprintf(prompt + strlen(prompt), "%d", GET_MAX_MANA(ch)); break; case 'v': // curr. move sprintf(prompt + strlen(prompt), "%d", GET_MOVE(ch)); break; case 'V': // max move sprintf(prompt + strlen(prompt), "%d", GET_MAX_MOVE(ch)); break; case 'c': case 'C': // credits(money) attributed to them sprintf(prompt + strlen(prompt), "%d", GET_GOLD(ch)); break; case 'a': case 'A': // AC sprintf(prompt + strlen(prompt), "%d/10", GET_AC(ch)); break; case 'x': // curr. exp. sprintf(prompt + strlen(prompt), "%d", GET_EXP(ch)); break; case 'X': // exp. to level sprintf(prompt + strlen(prompt), "%d", level_exp(GET_CLASS(ch), (GET_LEVEL(ch)+1)) - GET_EXP(ch)); break; case 'e': case 'E': [clipped for space reasons] break; // enemy cond. case 't': case 'T': [clipped for space reasons] break; // tank cond. case '_': // new line sprintf(prompt + strlen(prompt), "\r\n"); break; } // switch(c[1]) } // if(c[0] == '$') } // for(...) } // else if(!d->... sprintf(prompt + strlen(prompt), "> "); return(prompt); } else // if(!d->char... return("> "); // return > if there is no character linked to the desc } ________________________________________________________________ YOU'RE PAYING TOO MUCH FOR THE INTERNET! Juno now offers FREE Internet Access! Try it today - there's no risk! For your FREE software, visit: http://dl.www.juno.com/get/tagj. +------------------------------------------------------------+ | 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