Re: NEWBIE: spec_proc problems...

From: Hades (
Date: 05/14/96

> I am attempting to write a spec_proc for having guildmasters let you gain 
> levels. Note that i have correctly assigned the proc and gain_exp no 
> longer automatically raises levels when you have enough exp.  I created 
> the command "level" and the follwoing spec_proc called "guild_levels".
> ACMD(do_level)
> {
>   static char arg2[MAX_INPUT_LENGTH];
>   half_chop(argument, arg, arg2);
>   send_to_char("You can only gain levels in a guild.\r\n", ch);
> }
> The command works fine but when level is typed at a guildmaster it always 
> gets stuck at one part of the code and returns from there.  I am assuming 
> it is either the way i tried to handle 2 arguments or my misuse of is_abbrev.
> SPECIAL(guild_levels)
> {
>   static char arg2[MAX_INPUT_LENGTH];
>   int class;
>   if (IS_NPC(ch) || !CMD_IS("level"))
>     return 0;
>   if (GET_LEVEL(ch) >= LVL_IMMORT) {
>     send_to_char("Your already an Immortal!!\r\n", ch);
>     return 1;
>   }
>   if (!*arg) {

Here's your problem.... what's arg? it was never assigned. Specprocs get
'argument' passed to them. add:

one_argument(argument, arg);
right after:
int class;

that takes argument and finds the one argument you entered, and puts it in
arg. I'm sure you know that already (maybe not...) but for the newbies
reading this who DESERVE some help, it's nice to tell them.

That else if switch was checking arg, which was probably whatever it was
that was assigned to arg sometime earlier in the code. Try this... type kick
mage, it'll say that's nowhere to be seen or something, then type: level
crap. Or level <whatever>. I bet it does level mage. Then again I cioul;d be
completely wrong, because arg might get reassigned somewhere else but
whatever, that's what your problem was.

>   } else if (is_abbrev(arg, "bard")) {
>       class = CLASS_BARD;
>   } else {
>      send_to_char("usage: level <class> [gain]\r\n", ch);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> No matter what i type after level or even just level by itself i get this 
> message.  I changed the second occurence of this message to make sure 
> this waswhere it gets stuck and it is.
>      return 1;
>   }
>   if (!*arg2) {
>     sprintf(buf, "You need %d experience points to reach the next 
> level.\r\n", exp_for_level(GET_LEVELX(ch, class)));
>     send_to_char(buf, ch);
>     return 1;
>   } else if (is_abbrev(arg2, "gain")) {
>      if (GET_EXP(ch) >= exp_for_level(GET_LEVELX(ch, class))) {
>         GET_LEVELX(ch, class) += 1;


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