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 ➜ SMAUG coding ➜ locker code writing more than just the locker to the file

locker code writing more than just the locker to the file

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


Posted by Jason   (109 posts)  Bio
Date Tue 29 Apr 2014 09:46 PM (UTC)

Amended on Tue 29 Apr 2014 09:48 PM (UTC) by Jason

Message
ok on the mud I am making I pulled the locker code out of my old source and put it into my new source. The problem I am having is that if there are other objects laying in the floor of the room that the locker is in, then it writes those items to the locker files as well, then when a player opens the locker, you get a log message in the mud. I.E. 3 items on the floor when closed desk chair and rug. close locker... writes it to file, open locker:

LOG UNKNOWN LOCKER
LOG UNKNOWN LOCKER
LOG UNKNOWN LOCKER
You open your locker.


Here is the code that handles this process:

        act(AT_ACTION, "$n opens $s locker.",ch, NULL, NULL, TO_ROOM);
        act(AT_ACTION, "You open your locker.",ch, NULL, NULL, TO_CHAR);
    }
    else if( !str_cmp( arg, "close" ) )<-----From here down is the code that controls the saving of the locker
    {
        for( locker = ch->in_room->first_content; locker ; locker = locker->next_content )
	{
            if ( !str_cmp(locker->name, ch->name) ) break;
	}

	if (!locker)
	{
            send_to_char("That locker is not open.nr",ch);
            return;
	}
	else
	{
            act(AT_ACTION, "$n closes the locker.",ch, NULL, NULL, TO_ROOM);
            act(AT_ACTION, "You close the locker.", ch, NULL, NULL, TO_CHAR);
            fwrite_locker( ch, locker );
            extract_obj(locker);
        }
     }    
    return;    
}

void fwrite_locker( CHAR_DATA *ch, OBJ_DATA *locker )
{
    /* Variables */
    FILE *fp = NULL;
    char strsave[MAX_INPUT_LENGTH];
    char tch[MSL];

    if( !locker )
    {
	sprintf(tch, "Fwrite_locker: NULL object: %s", ch->name);
	log_string( tch );
       return;
    }
    	send_to_char("CHECK POINT FOURnr",ch);
    	sprintf( strsave, "%s%s", LOCKER_DIR, capitalize( ch->name ) );
   
    	if ( ( fp = fopen( strsave, "w" ) ) != NULL )
    	{
            fwrite_obj( ch, locker, fp, 0, OS_LOCKER, FALSE );
            fprintf( fp, "#END nr" ); 
            fclose( fp );
    	}
    return;
}



I put the check points in there so I could see what was happening. I'm not the best with loops yet.. but I am getting there.. I was inclined to think that I needed to separate_obj for the locker but that failed miserably for me.. could be that I did it wrong... Any suggests would be great.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 29 Apr 2014 10:00 PM (UTC)
Message
What messages do you see when you close the locker?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jason   (109 posts)  Bio
Date Reply #2 on Tue 29 Apr 2014 10:05 PM (UTC)

Amended on Tue 29 Apr 2014 10:06 PM (UTC) by Jason

Message
You close your locker... it doesn't send any other message out when it writes the file... When I had the checkpoints all in I would see it cycle the check points.

CHECKPOINT ONE
CHECKPOINT TWO
CHECKPOINT ONE
CHECKPOINT TWO
CHECKPOINT ONE
CHECKPOINT TWO
CHECKPOINT ONE
CHECKPOINT TWO
CHECKPOINT THREE
CHECKPOINT FOUR
You close your locker.


Which I know is where it cycled through all the objects into the room until it got to the one that matched the character name to the locker name.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 30 Apr 2014 08:57 PM (UTC)
Message
I can't see anything wrong there. Try running it with the debugger enabled:

http://www.gammon.com.au/gdb

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jason   (109 posts)  Bio
Date Reply #4 on Wed 30 Apr 2014 09:56 PM (UTC)
Message
Yeah I know... I saw nothing wrong with it either... It ran fine on my old mud which compiled in C but now I am having the issue running it in C++ although, I may not have had any other objects in the room at the same time when closing the lockers on the other mud.
Top

Posted by Jason   (109 posts)  Bio
Date Reply #5 on Wed 30 Apr 2014 10:01 PM (UTC)
Message
ok I'm a newb... I don't understand how to get the debugger to work with this code when it isn't causing a crash. any help?
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 01 May 2014 03:44 AM (UTC)
Message
My page mentions how to do that, see:

http://www.gammon.com.au/forum/?id=3653&reply=3#reply3

In particular you would do something like:


cd ../area
gdb ../src/smaug

(set some breakpoints)

run

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


21,611 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.