locker code writing more than just the locker to the file

Posted by Jason on Tue 29 Apr 2014 09:46 PM — 7 posts, 28,218 views.

#0
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.
Amended on Tue 29 Apr 2014 09:48 PM by Jason
Australia Forum Administrator #1
What messages do you see when you close the locker?
#2
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.
Amended on Tue 29 Apr 2014 10:06 PM by Jason
Australia Forum Administrator #3
I can't see anything wrong there. Try running it with the debugger enabled:

http://www.gammon.com.au/gdb
#4
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.
#5
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?
Australia Forum Administrator #6
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