Register forum user name Search FAQ

Gammon Forum

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 ➜ Compiling the server ➜ do_exits

do_exits

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Ithildin   USA  (262 posts)  Bio
Date Thu 18 Mar 2004 05:03 AM (UTC)
Message
i'm porting over my exits snippet to smaugfuss. i get a warning from cygwin on it.



act_info.c: In function `do_exits':
act_info.c:1757: warning: suggest parentheses around && within ||


here's the code from that area. i tried puttin parenthesis in other places, but i'm just not getting it. i hvaen't slept much lately so that's probably it.


for ( pexit = ch->in_room->first_exit; pexit; pexit = pexit->next )
    {
    if ( pexit->to_room
	  ||   IS_SET(pexit->exit_info, EX_CLOSED)
	  && (!IS_SET(pexit->exit_info, EX_WINDOW)
	  ||   IS_SET(pexit->exit_info, EX_ISDOOR))
	  &&  !IS_SET(pexit->exit_info, EX_HIDDEN) )
	{


any ideas?
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Thu 18 Mar 2004 05:12 AM (UTC)
Message
I think it's just trying to tell you to be "nice" about writing down the precedence.

That is:

a || b && c || d && e || f

should be written:

a || (b && c) || (d && e) || f

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #2 on Thu 18 Mar 2004 05:12 AM (UTC)
Message
here's the whole function if you need it.


void do_exits( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    EXIT_DATA *pexit;
    bool found;
    bool fAuto;

    set_char_color( AT_EXITS, ch );
    buf[0] = '\0';
    fAuto  = !str_cmp( argument, "auto" );

    if ( !check_blind(ch) )
	return;

    strcpy( buf, fAuto ? "&W&g[Exits:&W&g]" : "Obvious exits:\n\r&Y&g" );

    found = FALSE;
    for ( pexit = ch->in_room->first_exit; pexit; pexit = pexit->next )
    {
    if ( pexit->to_room	  
		||   IS_SET(pexit->exit_info, EX_CLOSED)	  
		&& (!IS_SET(pexit->exit_info, EX_WINDOW)	  
		||   IS_SET(pexit->exit_info, EX_ISDOOR))	  
there is line -->&&  !IS_SET(pexit->exit_info, EX_HIDDEN) )
	{
	    found = TRUE;
	    if ( fAuto )
	    {
		//strcat( buf, " " );
		//strcat( buf, dir_name[pexit->vdir] );
	        if ( pexit->to_room
			
			  && IS_SET(pexit->exit_info, EX_CLOSED))
			{  strcat( buf, " &W&g-#&Y&c" );
		      strcat(buf, dir_name[pexit->vdir]);
			}
			else 
			{   strcat( buf, " &W&g-&Y&c" );
		        strcat( buf, dir_name[pexit->vdir] );
			}
		}
	    else
	    {
		sprintf( buf + strlen(buf), "%-5s - %s\n\r",
		    capitalize( dir_name[pexit->vdir] ),
		    room_is_dark( pexit->to_room )
			?  "Too dark to tell"
			: pexit->to_room->name
		    );
	    }
	}
    }
	
	

    if ( !found )
	strcat( buf, fAuto ? " none.\n\r" : "None.\n\r" );
    else
      if ( fAuto )
	strcat( buf, ".\n\r" );
    send_to_char( buf, ch );
    return;
}





Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #3 on Thu 18 Mar 2004 05:19 AM (UTC)
Message
i'm sorry guys, this should be in coding. i wasn't paying attention.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #4 on Thu 18 Mar 2004 05:24 AM (UTC)
Message
Right... it's probably asking you to do this:


		if ( pexit->to_room	  
		|| (  IS_SET(pexit->exit_info, EX_CLOSED)	  
		&& (!IS_SET(pexit->exit_info, EX_WINDOW) )
  
		|| (  IS_SET(pexit->exit_info, EX_ISDOOR))	  
                &&  !IS_SET(pexit->exit_info, EX_HIDDEN) ) )

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #5 on Thu 18 Mar 2004 05:36 AM (UTC)
Message
still got the same warning.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #6 on Thu 18 Mar 2004 05:51 AM (UTC)
Message
Could you post the new offending code please? Just to be sure I have the "freshest" version. :)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #7 on Thu 18 Mar 2004 10:52 AM (UTC)

Amended on Thu 18 Mar 2004 11:03 AM (UTC) by Meerclar

Message

if 
( pexit->to_room 
|| 
(IS_SET(pexit->exit_info, EX_CLOSED) && !IS_SET(pexit->exit_info, EX_WINDOW))
||
(IS_SET(pexit->exit_info, EX_ISDOOR) && !IS_SET(pexit->exit_info, EX_HIDDEN))
)



Is what the code should look like to eliminate the warnings. Your original parenthesis were slightly off.

if 
( pexit->to_room
^1	  
||
IS_SET(pexit->exit_info, EX_CLOSED) && (!IS_SET(pexit->exit_info, EX_WINDOW)
      ^2                          ^2   ^3      ^4 (other 4 at end of line)
||
IS_SET(pexit->exit_info, EX_ISDOOR)  ) 
      ^5                          ^5 ^3
&&  
!IS_SET(pexit->exit_info, EX_HIDDEN)  )
       ^6                          ^6 ^1

Your third parenthetical set was throwing the whole check structure off and causing your warning.

(reformatted code so I could track paranthetical groupings more easily)

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #8 on Thu 18 Mar 2004 10:57 AM (UTC)
Message
Actually that's not right either, it doesn't follow the same logic... here is what seems to be the correct version...

(original)

	if ( pexit->to_room
	||   IS_SET(pexit->exit_info, EX_CLOSED)
	&& (!IS_SET(pexit->exit_info, EX_WINDOW)
	||   IS_SET(pexit->exit_info, EX_ISDOOR))
	&&  !IS_SET(pexit->exit_info, EX_HIDDEN) )


(reformatted, but not changed)


	if ( 
	pexit->to_room
	||   IS_SET(pexit->exit_info, EX_CLOSED)
	&& (
		!IS_SET(pexit->exit_info, EX_WINDOW)
		||   IS_SET(pexit->exit_info, EX_ISDOOR)
	   )
	&&  !IS_SET(pexit->exit_info, EX_HIDDEN) )


Therefore, to keep the same precedence with parentheses...



	if ( 
	pexit->to_room
	|| (
		IS_SET(pexit->exit_info, EX_CLOSED)
		&& (
			!IS_SET(pexit->exit_info, EX_WINDOW)
			||   IS_SET(pexit->exit_info, EX_ISDOOR)
		   )
		&&  !IS_SET(pexit->exit_info, EX_HIDDEN)
	   )
	)


Don't you just love icky code... they really could have formatted things better to make this more clear.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #9 on Thu 18 Mar 2004 11:19 AM (UTC)
Message
Better still would have been some comments so we know what he's actually trying to accomplish. I can't actually be sure if he's trying to check for closed windows and hidden doors (my edit) or just closed and hidden doors (Ksilyan's edit) or something else altogether. What the actual intent of the check is would determine the edit he needs to make to get rid of the warnings.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #10 on Thu 18 Mar 2004 11:59 AM (UTC)
Message
You're right... it looks like the way you wrote it, seems more like what he *meant*... I just wrote out the parentheses to respect the same precedence that he *wrote*.

Do what I mean, not what I said, eh? :-) Too bad compilers don't work that way...

But you're definitely correct that some comments about intention would've solved a *bunch* of problems here.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #11 on Thu 18 Mar 2004 12:53 PM (UTC)
Message
I'm sorry about not getting back to you guys. my internet started screwing up. couldn't get back on. plus it was late in the evening for me. i just woke up and i have to head out. but i'll be back later tonite. what my intent was to find if their was a door, and if there was, then it would put a # before the exit to show that it was closed. like this

[Exits: North #South}

south is a closed door. once you open it, the # goes away.

that same code worked without a problem on my smaug windows version. sorry for no elaboration. i'll be back later tonite, thanks for your help.

Ithildin
Top

Posted by Ithildin   USA  (262 posts)  Bio
Date Reply #12 on Fri 19 Mar 2004 12:34 AM (UTC)
Message
i put in ksilyan's code. it worked beautifully. Thanks so much guys. i really appreciate the help.

Ithildin
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.


34,751 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.