>= doesnt seem to be working

Posted by Rob Harper on Fri 26 Sep 2003 07:01 PM — 3 posts, 13,474 views.

#0
I'v been posting up a storm as of late, hope you guys can help me with this one too. My mud works on sublevels in a way and as a convience I tried to add a quick little gauge to let the players know how in a roundabout way close they are to the next sublevel. But it doesnt seem to be working?

The way I have it laid out is somthing like:

void do_stat( CHAR_DATA *ch, char *argument )
{

char buf[MAX_STRING_LENGTH];


if (ch->level >= 2)
sprintf(buf, "20 to ");
else if (ch->level >= 4)
sprintf(buf, "40 to ");
else if (ch->level >= 6)
sprintf(buf, "60 to ");
else if (ch->level >= 8)
sprintf(buf, "80 to ");
else if (ch->level >= 10)
sprintf(buf, "0 to ");
else if (ch->level >= 12)
sprintf(buf, "20 to ");
else if (ch->level >= 14)
sprintf(buf, "40 to ");
else if (ch->level >= 16)
sprintf(buf, "60 to ");
else if (ch->level >= 18)
sprintf(buf, "80 to ");
else if (ch->level >= 20)
sprintf(buf, "0 to ");

And it continues on like that then I somthing like this at the very bottom.
pager_printf(ch, "Precent to better Build: %s \n\r", buf );

Kind of slopy I know but I figured it would do the job for now, but it doesnt seem to be working? The "# to whatever level never changes". I guess it's another one of those things that when someone points me in the right directions it'll make me a much better coder heh. But till then it puzzles me as to why it's not working seems simple enough.

Thanks
Amended on Fri 26 Sep 2003 07:12 PM by Rob Harper
USA #1
Well, work through your code logically. Let's assume that ch->level is equal to 15.

We come on to your ifcheck, and the very first check is:

if ( ch->level >= 2 )

This results in true, and therefore none of the else checks/blocks are even looked at.

What you want to do is have it the other way around: first check for the highest numbers, and go down.

e.g.

if ( ch->level >= 20 )
    // do something
else if ( ch->level >= 18 )
    // do something
else if ( ch->level >= 16 )
    // do something
/* etc. */


This way, it'll "trigger" the right ifcheck (if I may use that word) and so you won't end up matching on the very first one.
#2
Oh my, I feel like such a ditz now. I had no idea the order had anything to do with it, thanks for the help.

Thanks again