I realized that I didn't send my reply to the whole list, so first off,
here's the solution:
if ( (!IS_NPC(to) && to->desc == NULL )
|| ( IS_NPC(to) && !HAS_TRIGGER(to, TRIG_ACT) )
|| (to->position < min_pos && !to->desc) )
continue;
Now the explanation.
Learning how to "code" and learning how to "program" are really two
different things. A monkey can code. Programming, which is what "coding"
is really about, is more an act of problem solving than it is of writing
actual lines of code. Take your problem for example. Your original code is
this:
if ( (!IS_NPC(to) && to->desc == NULL )
|| ( IS_NPC(to) && !HAS_TRIGGER(to, TRIG_ACT) )
|| to->position < min_pos
&& !to->desc )
continue;
Forget about code and look at it like a problem, consider the fact that the
compiler is basically saying that it's confused and read the problem. I
will use boolean algebra in my analysis, so * is equal to && and + is equal
to ||.
Basically your code says the following:
(A * B) + (C * D) + E * F
Now since the compiler doesn't evaluate in the same order that regular math
is done, you can see a problem with the last part: + E * F. The whole part
is sort of ambiguous, do we do (A * B) + (C * D) + E first, then AND the
result with F? Or should we AND E and F first, then OR that result with (A
* B) + (C * D)? I think you see what I'm getting at here.
In looking at this problem, you can see that there are parenthesis required
around E * F for the sake of clarity, ensuring that you really want E AND F
before ORing with the rest of the "equation".
I hope I explained this well for you. Anyone can learn to write lines of
code. You won't be able to "program" until you master the art of problem
solving.
-Ralgha
----- Original Message -----
From: "Dantin" <[EMAIL PROTECTED]>
To: "Rom Mailing List" <[email protected]>; "Ralgha" <[EMAIL PROTECTED]>
Sent: Tuesday, July 09, 2002 10:47 PM
Subject: Re: Suggest Parenthisese around || and &&
> How did you come by that solution? It compiled without a complaint..
I'm
> just trying to grasp solutions for further evaluation while learning to
> code. Thanks for your help!
>
> Dantin
>
> ----- Original Message -----
> From: "Ralgha" <[EMAIL PROTECTED]>
> To: "Dantin" <[EMAIL PROTECTED]>
> Sent: Tuesday, July 09, 2002 11:28 PM
> Subject: Re: Suggest Parenthisese around || and &&
>
>
> > if ( (!IS_NPC(to) && to->desc == NULL )
> > || ( IS_NPC(to) && !HAS_TRIGGER(to, TRIG_ACT) )
> > || (to->position < min_pos && !to->desc) )
> > continue;
> >
> > That'll work. :)
> >
> > -Ralgha
> >
> > ----- Original Message -----
> > From: "Dantin" <[EMAIL PROTECTED]>
> > To: "Rom Mailing List" <[email protected]>
> > Sent: Tuesday, July 09, 2002 10:08 PM
> > Subject: Suggest Parenthisese around || and &&
> >
> >
> > > Okay here is the code:
> > >
> > > for( ; to ; to = to->next_in_room )
> > > {
> > > --> if ( (!IS_NPC(to) && to->desc == NULL )
> > > -->|| ( IS_NPC(to) && !HAS_TRIGGER(to, TRIG_ACT) )
> > > --> || to->position < min_pos
> > > -->--> && !to->desc )
> > > continue;
> > >
> > > if( ( type == TO_CHAR ) && to != ch )
> > > continue;
> > > if( type == TO_VICT && ( to != vch || to == ch ) )
> > > continue;
> > > if( type == TO_ROOM && to == ch )
> > > continue;
> > > if( type == TO_NOTVICT && (to == ch || to == vch) )
> > > continue;
> > >
> > > The part of the code that has a double --> is what I put in. It
> gives
> > > me a warning that suggest parentheses. What can I do to fix that.
Please
> > oh
> > > please help.. Don't flame either. Or Help and flame at the same time
> thats
> > > fair.. hehehe Thanks
> > >
> > > Dantin
> > >
> > >
> > >
> > > --
> > > ROM mailing list
> > > [email protected]
> > > http://www.rom.org/cgi-bin/mailman/listinfo/rom
> > >
> >
>