02 Nov, 2011, arholly wrote in the 1st comment:
Votes: 0
Hello:
I'm having a serious problem with my note system and it is a hot mess. The way the system was designed, our Note, Background, Fact, and Article system all use the note editors. After I thought I fixed the article system (a few threads back), things were going good. Then, really all of a sudden, it seems the articles replaced everything in the notes and backgrounds. Now, for some reason, it has not replaced anything in the facts, but that might be because I haven't added any facts.

It's like it is loading the article into everything. I can delete them and it does not change note.txt file, bg.txt file, etc… I even created a command to force the saving of those items and it doesn't change the file.

So, I tried deleting the bg.txt file (for example), where backgrounds are saved to. Then, I created a test command (below), to force it to save. And it saved the freakin' article over it. So, it has to be the way it is saving notes, right?
void do_save_info( CHAR_DATA *ch, char *argument )
{
save_notes(NOTE_BACKGROUND);
save_notes(NOTE_KNOWLEDGE);
}


This is the save_note function. Is something wrong?
void save_notes(int type)
{
FILE *fp;
char *name;
NOTE_DATA *pnote;

switch (type)
{
default:
return;
case NOTE_NOTE:
name = NOTE_FILE;
pnote = note_list;
break;
case NOTE_BACKGROUND:
name = BG_FILE;
pnote = bg_list;
break;
case NOTE_KNOWLEDGE:
name = KNOW_FILE;
pnote = know_list;
break;
case NOTE_ARTICLE:
name = NEWS_FILE;
pnote = news_list;
break;
}

fclose( fpReserve );
if ( ( fp = fopen( name, "w" ) ) == NULL )
{
perror( name );
}
else
{
for ( pnote = news_list; pnote != NULL; pnote = pnote->next )
{
if(type == NOTE_NOTE) {
fprintf( fp, "Sender %s~\n", pnote->sender);
fprintf( fp, "Date %s~\n", pnote->date);
fprintf( fp, "Stamp %ld\n", pnote->date_stamp);
fprintf( fp, "To %s~\n", pnote->to_list);
fprintf( fp, "Subject %s~\n", pnote->subject);
}
else if(type == NOTE_BACKGROUND || type == NOTE_KNOWLEDGE)
{
fprintf( fp, "Author %s~\n", pnote->sender);
fprintf( fp, "Date %s~\n", pnote->date);
fprintf( fp, "Stamp %ld\n", pnote->date_stamp);
fprintf( fp, "Keyword %s~\n", pnote->to_list);
fprintf( fp, "Diff %s~\n", pnote->subject);
}
else
{
fprintf( fp, "Author %s~\n", pnote->sender);
fprintf( fp, "Date %s~\n", pnote->date);
fprintf( fp, "Stamp %ld\n", pnote->date_stamp);
fprintf( fp, "Categ %s~\n", pnote->to_list);
fprintf( fp, "Subject %s~\n", pnote->subject);
}
sprintf( log_buf, "pnote-> subject = %s, pnote-> successes =%d", pnote->subject, pnote->successes);
log_string( log_buf );
fprintf( fp, "Success %d~\n", pnote->successes);
fprintf( fp, "Text\n%s~\n", pnote->text);
}
fclose( fp );
fpReserve = fopen( NULL_FILE, "r" );
return;
}
}


I'm really confused by this and it has cost me some amount of work loss, so I'm really trying to get this to work right.
02 Nov, 2011, David Haley wrote in the 2nd comment:
Votes: 0
It could also be the various linked lists or the filenames. Impossible to tell from just that.
02 Nov, 2011, arholly wrote in the 3rd comment:
Votes: 0
OK, so how would I tell?

This is the file name information.
#define NOTE_FILE		"../data/notes.txt"		/* For 'notes'*/
#define BG_FILE "../data/bg.txt" /* For 'backgrounds'*/
#define KNOW_FILE "../data/know.txt" /* For 'backgrounds'*/
#define NEWS_FILE "../data/news.txt" /* For 'articles'*/
#define PAPER_FILE "../data/paper.txt" /* For 'newspapers'*/
02 Nov, 2011, David Haley wrote in the 4th comment:
Votes: 0
You'll have to see how you're initializing and maintaining those linked lists. My guess is that pointers are being mixed up somewhere and you're storing articles in your notes list.
02 Nov, 2011, arholly wrote in the 5th comment:
Votes: 0
Which means what? I'm not a terribly well-learned programmer (learning on the job type). Any help would be great.
02 Nov, 2011, arholly wrote in the 6th comment:
Votes: 0
Err…OK, I think I got it fixed.
for ( pnote = news_list; pnote != NULL; pnote = pnote->next )
{
if(type == NOTE_NOTE) {

The first line was specifying news_list, so it was going and repopulating information that way. I removed that (which is the way it is in stock rom) and it seemed to have fixed the problem.

Thanks though David.
02 Nov, 2011, David Haley wrote in the 7th comment:
Votes: 0
Oh yeah. You were picking the right pnote list, but then discarding it with that for loop. I missed that with my quick skim… I saw the first part and assumed you were using that pnote assignment later.
02 Nov, 2011, arholly wrote in the 8th comment:
Votes: 0
Yeah, me too. Sometimes I forgot to go compare things in ROM and then see the differences what might work to fix. I appreciate the help though.
0.0/8