Hey guys... this one is severely hurting my head. If never been too good at
the general concept how mobprogs work, and all about the call_levels and
state[level] and cond[level]. I have OLC 1.81 with the Obj/Room progs
addon. My problem was trying to make an elseif statement(like the else if
in C) so i read through, and tried to get the gist of it, and tried it...
and tried again, and again... You get the picture... this is the
best/closest i think:
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 );
return;
}
state[level] = BEGIN_BLOCK;
if ( ++level >= MAX_NESTED_LEVEL )
{
prog_error( mob, obj, room, "Max nested level exceeded",
mvnum, ovnum, rvnum, pvnum );
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 ;
}
}
Two things off the bat... earlier i added an ifnot statement and i had to
change the cmd_eval_ functions to return 1 (true) 0 (false) and -1 (error)
because it just used 0 for errors, so thats what my qbool is doing there,
second i made a function to interpret errors(for my own benifit, tryinf to
read the code, alot easier with one function call then 3 if statmnets with
bug calls. right now what i test my function the elseif works(i think) but
then the else after it works too. I feel im -><- close to actually
understanding what im doing... but i need a push in the right direction. If
anyone sees any errors in the code i'd love to get it fixed, but im just as
interested in understanding the OLC/mobprogs stuff i added a while back and
have been slowly going through.
heres the mobprog i tried it with.
GRALL 100
if isnpc $n
say hi npc!
elseif ispc $n
say hi pc!
else
say who the **** are you?
endif
When I walk in the room this is what i get:
A trainer is here to teach various skills and spells.
a trainer says 'hi pc!'
a trainer says 'who the **** are you?'
If you need any more information I'll provide anything :)
-Josh