the problem is this: elseif isnt else then the next line if... because you
can do a bunch of things with it.

if level $n == 105
    say welcome IMP.
elseif level $n > 100
    say welcome immortal
elseif level $n == 100
    say hello hero
else
    say hello mudder
endif

thats different from:

if level $n == 105
    blah
else
    if level $n >100
         blah
    else
        if level $n ==100
            blah
        else
            blah
        endif
    endif
endif

see how much convoluted and the required endifs, and the nesting level
changes?

-Josh
----- Original Message -----
From: "Ammaross Danan" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, April 30, 2002 3:04 PM
Subject: RE: Mobprog problem - Elseif


> I am no master at mobprogs (actually quite the opposite), but I think I
have
> an idea to your problem.
> First off, the elseif in this basically:
> if something
> {
> code
> }
> else
> {
> if something
> code
> }
>
> And if you will notice, that takes you in one nested level.
> Also, the else part of your elseif is depenant on the last if-check being
> FALSE, so you need to use cond in there somewhere.
>
> > else if( !str_cmp( control, "elseif" ) )
> >         {
> >            int qbool;
> >
> >            if ( !level || state[level-1] != BEGIN_BLOCK )
> >            {
> >               prog_error( mob, obj, room, "elseif without if",
> >                           mvnum, ovnum, rvnum, pvnum );
>
> call_level--;
> >               return;
> >            }
> >
> >            state[level] = BEGIN_BLOCK;
> >
> >            if ( ++level >= MAX_NESTED_LEVEL )
> >            {
> >               prog_error( mob, obj, room, "Max nested level exceeded",
> >                           mvnum, ovnum, rvnum, pvnum );
>
> call_level--;
> >               return;
> >            }
> >
> >            line = one_argument( line, control );
> >
> >            if ( mob && ( check = keyword_lookup( fn_keyword,
> > control ) ) >=
> > 0 )
> >            {
> >               qbool = cmd_eval_mob( pvnum, line, check, mob, ch,
> > arg1, arg2,
> > rc$
> >            }
> >            else if ( obj && ( check = keyword_lookup( fn_keyword,
> > control ) ) >$
> >            {
> >               qbool = cmd_eval_obj( pvnum, line, check, obj, ch,
> > arg1, arg2,
> > rc$
> >            }
> >            else if ( room && ( check = keyword_lookup( fn_keyword,
> > control ) ) $
> >            {
> >               qbool = cmd_eval_room( pvnum, line, check, room, ch, arg1,
> > arg2, $
> >            }
> >            else
> >            {
> >               prog_error( mob, obj, room, "invalid if_check (elseif)",
> >                           mvnum, ovnum, rvnum, pvnum );
> >               return;
> >            }
> >            state[level] = END_BLOCK;
> >            cond[level] = (cond[level-1] == TRUE) ? FALSE : qbool > 0 ;
>
> cond[level] = (qbool > 0) ? TRUE : FALSE;
> >         }
> > }
> >
>
> > GRALL 100
> >
> > if isnpc $n
> >     say hi npc!
> > elseif ispc $n
> >     say hi pc!
> > else
> >     say who the **** are you?
> > endif
> >
>
> You could just do
> if isnpc $n
> say hi npc!
> else
> if ispc $n
> say hi pc!
> else
> say who the **** are you?
> endif
> endif
>
>
> But oh well. Try the fixes above and see if that gets you any closer. Try
> stepping through your program_flow using GDB while running the script and
> see if that helps you any.
> I have not tried the fixes myself, so they are not guarenteed to work.
>
> Ammaross Danan
>
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom


Reply via email to