17 Oct, 2011, plamzi wrote in the 21st comment:
Votes: 0
arholly said:
OK, it's just not saving. I went into the txt file it get's saved in and manually incremented it up one. It shows it is being incremented up one when I supress the article and down one when I promote the article, but it is definitely not saving across reboots.


Next thing I would do is to make sure the function loading the articles points to the same file (the one defined by NOTE_FILE).
17 Oct, 2011, arholly wrote in the 22nd comment:
Votes: 0
OK, this just shows my ignorance, but when I put this into Eclipse, it is giving me a warning for the media_suppress command. It says pnote might be used uninitialized in this function? Is that a problem?

And wouldn't the function loading the articles point to the same file if after I manually change the suppression level in the file it show the level after a reboot?
17 Oct, 2011, Rarva.Riendf wrote in the 23rd comment:
Votes: 0
Quote
It says pnote might be used uninitialized in this function

It is a potential problem nod. Means that it can use the value and do random thing as the value means nothing.


In your project properties you need to change the C/C++ default build command to
make -f Makefile

and the all that is mising is something like that:
#!/bin/sh
# Makefile for Solaris 2.1 on a Sparc 10 with gcc.
# Changes contributed by Torsten Spindler.
# To use standard MERC mobprogs, comment out the -DMPROG_NEW
DATE=`date +%m%d%Y`
CC = gcc
PROF = -ggdb -lm
C_FLAGS = -Wall $(PROF) -Dlinux
L_FLAGS = -lcrypt -lpthread


# SYSTEM = #-DMPROG_NEW

O_FILES = threadedcommand.o livemaze.o mapmakerv2.o act_comm.o act_info.o act_move.o\
act_obj.o act_wiz.o alias.o fileutils.o anmagic.o anmagic2.o anmagic3.o\
anskills.o bit.o clans.o comm.o const.o color.o craft.o db.o db2.o effects.o\
fight.o flags.o handler.o interp.o note.o magic.o magic2.o mob_comm.o\
mob_prog.o misc.o olc.o olcmem.o olcsave.o recycle.o protocol.o\
save.o skills.o special.o string.o tables.o track.o update.o \
www.o anobjcraft.o event.o
all: $(O_FILES)
$(CC) -o anrun $(O_FILES) $(L_FLAGS)
gcc –version
mv *.o ../ANBuildResult
mv anrun ../ANBuildResult

.c.o: an.h
$(CC) -c $(C_FLAGS) $<

clean:
rm -f *.o
rm -f anrun
rm -f ../ANBuildResult/*.o
rm -f ../ANBuildResult/anrun
17 Oct, 2011, plamzi wrote in the 24th comment:
Votes: 0
arholly said:
And wouldn't the function loading the articles point to the same file if after I manually change the suppression level in the file it show the level after a reboot?


From your initial description, I wasn't clear which function had no effect. If the loader seems to read from the right file, then check if the saver points to the same file.
17 Oct, 2011, Vatiken wrote in the 25th comment:
Votes: 0
Do you know for sure it isn't saving? In other words, have you determined with 100% certainty that the problem has nothing to do with LOADING the data?

Have you placed calls in your save function to alert you each time that function is called? And if so, is the data entering the save function up-to-date?

I noticed you are writing your data with '%d~', the '~' is typically reserved for marking the end of string and should NOT be used for digits. Depending on how your server reads it's data, this could cause problems.
18 Oct, 2011, arholly wrote in the 26th comment:
Votes: 0
@Vatiken:
Do I know for sure it is not saving. I'm reasonably sure. These are the steps I do to check.
Look at the text file first to see what the level is.
The run the command in game to suppress it. It should set it to whatever level I tell it to. If I do article read # of the article suppressed, it displays for me the level I told it to be.
When I look at the text file though, it is not showing it being any different (still 0 ).

If I manually set it to whatever I want it to be in the text file and restart the mud, it displays the suppression level at whatever I manually set it to.

No, I have not placed calls. How would I do that?

So, should I not have the ~ there? Should I remove that from the save function?

I appreciate all this help and all the support you are giving. I am learning, but I'm still pretty green.
18 Oct, 2011, plamzi wrote in the 27th comment:
Votes: 0
In save_notes, replace:

for ( ; pnote != NULL; pnote = pnote->next )


with:

for ( pnote = news_list; pnote != NULL; pnote = pnote->next )


If it throws an error that news_list is undefined, copy the declaration of news_list from the file where media_suppress resides.
18 Oct, 2011, arholly wrote in the 28th comment:
Votes: 0
Replaced as asked, make clean, compile, no errors concerning that.

Arholly
18 Oct, 2011, plamzi wrote in the 29th comment:
Votes: 0
arholly said:
Replaced as asked, make clean, compile, no errors concerning that.

Arholly


But does it fix the problem? :)
18 Oct, 2011, Vatiken wrote in the 30th comment:
Votes: 0
What i mean by a "call" is any means of the program letting you, the user, know something relevant. I'm not overly familiar with ROM, but as I used to use Circle I expect you'd have a command similar to log(), or log_string(), syslog() or bug(), or some other means of sending a message to all Immortals in the game. If I were facing a similar problem, and I determined that:
A) The variable in question is set to "X" in media_suppress()
B) The variable in question is no longer set to "X" after the mud reboots.

Then I would place a "call" somewhere between point A and point B, perhaps in your case here:
for ( ; 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);
}
+++ syslog("pnote-> subject = %s, pnote-> successess =%d", pnote->subject, pnote->successes); +++
fprintf( fp, "Success %d~\n", pnote->successes);
fprintf( fp, "Text\n%s~\n", pnote->text);
}


This way, when it does reach this point in the code, I, the user, will be informed as to which "pnote" is being saved, and the current status of the "successes" variable.

If I see this message, and the variable is "as it should be", then whatever is causing the problem is after this point, and this is my new point (A).
If the variable is "not as it should be", then the problem is before this point, and you now have a new point (B).
Or, and i'd say this is the most likely situation, you WON'T see this message, and that means you are not reaching this point in the code, which still gives you a new (B).

If you're not seeing the message, or even if you are, I personally would create (or always have) a "test" command, which is accessible to the coder. Basically just an empty command that you can use whenever you need to test something. And then, "suppress" the paper, and make the "test" command call the save function for that "type" of item… NOTE_ARTICLE?

void do_test( CHAR_DATA *ch, char *argument )
{
save_notes(NOTE_ARTICLE);
}

If the save function works, and upon reboot the variable is "as it should be", then you can rule out the save function as the culprit.

At this point, you can be pretty certain that you are just missing a call to your save function somewhere.

With regards to '~', no, it should NOT be there. The purpose of the '~' is for your string reading function, it will collect every char up until it finds '~', and then it stops.
fprintf( fp, "Date    %s~\n", pnote->date);              <——- Needs '~'
fprintf( fp, "Stamp %ld\n", pnote->date_stamp); <——- Doesn't.


Hope this helps some.
18 Oct, 2011, arholly wrote in the 31st comment:
Votes: 0
OK, let's see where I can start with this.
@plamzi: No, it did not fix the problem.

@Vatiken:
Implemented your suggestion and guess what, this is what the log showed. I logged all my commands, just so I could get the full feel.
Quote
Tue Oct 18 07:57:29 2011 - Log Rayal: testarticle
Tue Oct 18 07:57:29 2011 - pnote-> subject = Test, pnote-> successes =1
Tue Oct 18 07:58:02 2011 - pnote-> subject = Test, pnote-> successes =1
Tue Oct 18 07:58:05 2011 - Log Rayal: timerclear
Tue Oct 18 07:58:09 2011 - Log Rayal: timerclear rayal
Tue Oct 18 07:58:14 2011 - Log Rayal: testarticle
Tue Oct 18 07:58:14 2011 - pnote-> subject = Test, pnote-> successes =2


I was then encouraged because it was saving the successes when I forced it with the testarticle command. So, I rebooted and it was still set at 2. Which means that it is not a problem with the saving since when forced to save, it is clearly saving.

Now though, I am a bit confused. It should be saving in the media_supress command, but it obviously isn't. So what is going wrong then because when I manually force it to save, it does, but not when it should be automatically.
int media_suppress(CHAR_DATA *ch, char *argument)
{
int fail = dice_rolls(ch, ch->influences[INFL_MEDIA], 8);
char buf[MAX_STRING_LENGTH];
int anum, vnum;
NOTE_DATA *pnote;

if(argument[0] == '\0' || !is_number(argument))
{
send_to_char("Which article are you trying to suppress?\n\r", ch);
return FALSE;
}

if(fail > 0)
{
anum = atoi( argument );
vnum = 0;
for ( pnote = news_list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) && vnum++ == anum )
{
sprintf(buf, "You arrange the suppression of '%s'.\n\r",
pnote->subject);
send_to_char(buf, ch);
pnote->successes += fail;
ch->influences[INFL_MEDIA]–;
return TRUE;
}
}

sprintf(buf,"There aren't that many articles.\n\r");
send_to_char(buf,ch);
return FALSE;
}
else if(fail == 0)
{
send_to_char("Your wiles fail to suppress the article.\n\r", ch);
ch->influences[INFL_MEDIA]–;
}
else
{
send_to_char("You offend some members of the media.\n\r", ch);
ch->influences[INFL_MEDIA] -= UMIN(2, ch->influences[INFL_MEDIA]);
}

ch->infl_timer = 5;
/* Added this so it will force the saving of the suppression */
save_notes(NOTE_ARTICLE);
return TRUE;
}
18 Oct, 2011, Vatiken wrote in the 32nd comment:
Votes: 0
if(fail > 0)
{
anum = atoi( argument );
vnum = 0;
for ( pnote = news_list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) && vnum++ == anum )
{
sprintf(buf, "You arrange the suppression of '%s'.\n\r",
pnote->subject);
send_to_char(buf, ch);
pnote->successes += fail;
ch->influences[INFL_MEDIA]–;
return TRUE;
}
}

sprintf(buf,"There aren't that many articles.\n\r");
send_to_char(buf,ch);
return FALSE;
}


At this point I'd scatter some calls through your function to track exactly the path your program takes when you execute it.

That being said, by the look of your code, it would appear due to your "return XXX" that if "fail > 0" you won't reach save_note().
18 Oct, 2011, arholly wrote in the 33rd comment:
Votes: 0
OK, I know the easy work-around is to add the save_notes in the fail>0 section like this:
if(fail > 0)
{
anum = atoi( argument );
vnum = 0;
for ( pnote = news_list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) && vnum++ == anum )
{
sprintf(buf, "You arrange the suppression of '%s'.\n\r",
pnote->subject);
send_to_char(buf, ch);
pnote->successes += fail;
ch->influences[INFL_MEDIA]–;

/* Added this so it will force the saving of the suppression */
save_notes(NOTE_ARTICLE);
return TRUE;
}
}

sprintf(buf,"There aren't that many articles.\n\r");
send_to_char(buf,ch);
return FALSE;
}

Is that what I should be doing? I mean, I tried it and it works, but I want to make sure I'm not hosing something up by doing it that way.
18 Oct, 2011, arholly wrote in the 34th comment:
Votes: 0
Ok, found out that because it's all tied into the note function, doing it save_notes(NOTE_ARTICLE) replaced all the notes with whatever was in the articles. Replaced it with save_notes(pnote->type); and it fixed it. Don't like that one bit.

Yikes. I'm going to need to break these apart down the road so I can avoid this kind of issue in the future.
18 Oct, 2011, Vatiken wrote in the 35th comment:
Votes: 0
Matter of opinion. As it appears to be the only place in your media_suppress() where the note gets changed it makes sense to keep it there.

On the other hand, if this a function that is called constantly it might be better to implement a routine that searches through all the notes and saves the altered ones every 1, 2, 5, 10 minutes or what-have-you. Or make a list of just altered notes and run through that list every X minutes.

Saving to the harddisk is somewhat "cpu intensive" and should probably be avoided if unnecessary. That being said, unless being done on a massive scale, probably going to go unnoticed.
18 Oct, 2011, arholly wrote in the 36th comment:
Votes: 0
It's definitely not called constantly. It's only called when someone uses their influence to try and suppress/promote a media article, so it doesn't happen terribly frequently.
18 Oct, 2011, arholly wrote in the 37th comment:
Votes: 0
One last thing on this. It gives me a warning in eclipse saying pnote might be unintialized in this function? What does this mean and how do I make it fine?

And thank you all for your help again.
18 Oct, 2011, Vatiken wrote in the 38th comment:
Votes: 0
int x;

x += 1;

"x" would be considered unitialized here b/c I have attempted to access and/or modify the variabe without first initializing it.

To initialize it, at some point before accessing it, I must set it.

Example:
int x = 0;
Or
int x;
x = 0;

Edit: it can be set to anything, not just 0.
18 Oct, 2011, plamzi wrote in the 39th comment:
Votes: 0
arholly said:
One last thing on this. It gives me a warning in eclipse saying pnote might be unintialized in this function? What does this mean and how do I make it fine?

And thank you all for your help again.


It should be a harmless warning, but if you change the initialization at the top, it should go away:

NOTE_DATA *pnote = note_list;
18 Oct, 2011, arholly wrote in the 40th comment:
Votes: 0
Oh, ok. I get it. Thanks. Yes, that does it.
20.0/41