Re: do_improve

From: Hades (tourach@cyber2.servtech.com)
Date: 03/20/96


Ok, first off let's straighten out your code... move the }'s to the lines
they should be on to make it less confusing looking.
> 
> ACMD(do_improve)
> {
>    one_argument(argument, arg);
> 
>    if (isname("str", arg)) {
>         if (ch->real_abils.str < 18) {
>                 ch->real_abils.str = ch->real_abils.str + 1;
>                 GET_STR(ch) = GET_STR(ch) - 5;
          } else
>                 sprintf(buf, "Already at 18.\r\n");
>    }

     if (isname("stradd", arg)) {
>         if (ch->real_abils.str_add < 100) {
>                 ch->real_abils.str_add = ch->real_abils.str_add + 10;
>                 GET_ADD(ch) = GET_ADD(ch) - 2;
>         } else
>                 sprintf(buf, "Already at 100.\r\n");
>    }

>    if (isname("dex", arg)) {
>         if (ch->real_abils.dex < 18) {
>                 ch->real_abils.dex = ch->real_abils.dex + 1;
>                 GET_DEX(ch) = GET_DEX(ch) - 5;
>         } else
>                 sprintf(buf, "Already at 18.\r\n");
>    }
>    if (isname("wis", arg)) {
>         if (ch->real_abils.wis < 18) {
>                 ch->real_abils.wis = ch->real_abils.wis + 1;
>                 GET_WIS(ch) = GET_WIS(ch) - 5;
>         } else
>                 sprintf(buf, "Already at 18.\r\n");
>    }
>    if (isname("int", arg)) {
> /* AT THIS POINT IT TELLS ME THERE IS A PARSE ERROR BEFORE 'int' */
> /* however, this line is no different from the rest of lines like it
> except that it has 'int' instead of 'dex' or what ever.  I don't get it.*/
>         if (ch->real_abils.int < 18) {
>                 ch->real_abils.int = ch->real_abils.int + 1;
>                 GET_INT(ch) = GET_INT(ch) - 5;
>         } else
>                 sprintf(buf, "Already at 18.\r\n");
>    }
I really needent format the rest...

Ok, your problem is that 'int' is a reserved word in c. It sees int, it's
expecting a variable name to be defined afterwards. Change it to intel or
something other than int and you'll be fine. The other parse errors are
caused by that int. Generally, if you have one single parse error, you are
almost gaurenteed to have a ton after that. Fix the first, and the rest all
fall into place.

Second, and I'm sure you haven't noticed it, but... it seems this command is
used to increase a stat. Do you realize  that you are increasing it by 1,
then reducing it by 5? 

Secondly... I deletd the end of this, so I'm not positive if it was there or
not, but:
sprintf(buf, "Alfready at 18");

Does absolutely nothing whatsoever except put that string into the variable
buf. For the char to see it you would need to use send_to_char.

Not to sound critical or anything, but this code could really use some
improvement... such as:
if the arg WAS 'str' then WHY bother to check if it was intel, wis, dex,
etc? Your code will play with the str stat, then continue on to check for
others. I suggest this:

  if (isname("str", arg)) {
    if (ch->real_abils.str < 18) {
      ch->real_abils.str++;  /* This will increase the value by 1 */
      GET_STR(ch) -= 5;  /* This will decrease it by 5. I suggest a book
    } else                  on C to learn these shortcuts. */
      sprintf(buf, "Already at 18.\r\n");
    return;  /* returns from do_improve to avoid further checking */
  }

One final thing, your indentation is way exaggerated. 2 spaces per line is
'standard' some prefer 3. But using 10 like that makes deeply nested if and
do and for statements get really hard to read. Although cosmetic only, it
does make your code easier to read if it's not as highly indented, and also
putting the { on the same line as the code makes it easier to read, but that
is personal prefrence also.

Don't take this as a flame, or that I'm ragging on you, just offering some
constructive criticism, I was a newbie at coding once too, and my god was my
code ugly :)

Hmm... my code STILL IS ugly :P but it works :)

Hades of Ebon Mists - 204.181.11.243 8888
		      ebonmists.roc.servtech.com 8888



This archive was generated by hypermail 2b30 : 12/07/00 PST