Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Mprog Boolean Evaluation
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Gohan_TheDragonball
USA (183 posts) Bio
|
Date
| Thu 24 May 2007 08:19 AM (UTC) |
Message
| This is a similar function to mprog_seval and mprog_veval but it will evaulate a boolean. Stock smaug had originally just evaluated ifchecks for a given circumstance and just returned without being able to use an operator and a value, value being true or false. To overcome this builders would have to create an ELSE clause, and not every ifcheck did something in an ELSE situation
For example:
if isfight($n)
break
else
if rand(10)
yawn
endif
endif
The following function will allow you to do something shorter like so:
if isfight($n) == false
if rand(10)
yawn
endif
endif
// Boolean Evaluation
bool mprog_beval( bool lhs, char *opr, char *rhs, CHAR_DATA *mob )
{
char log_buf[MAX_STRING_LENGTH];
bool rval;
if ( rhs[0] == '\0' )
return lhs;
else if ( !str_cmp( rhs, "true" ) )
rval = TRUE;
else if ( !str_cmp( rhs, "false" ) )
rval = FALSE;
else
return lhs;
if ( opr[0] == '\0' )
return lhs;
if ( !str_cmp( opr, "==" ) )
return ( bool )( lhs == rval );
if ( !str_cmp( opr, "!=" ) )
return ( bool )( lhs != rval );
sprintf( log_buf, "Improper MOBprog operator '%s' for Boolean Evaluation", opr );
progbug( log_buf, mob );
return lhs;
}
Now in mud_prog.c for the ifchecks you will change to the following, I will show you isfight as the example:
Original Code:
if ( !str_cmp(chck, "isfight") )
{
return who_fighting(chkchar) ? TRUE : FALSE;
}
This now becomes:
if ( !str_cmp(chck, "isfight") )
{
return mprog_beval( (who_fighting(chkchar) != NULL), opr, rval, mob );
}
| Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
7,861 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top