14 Oct, 2011, arholly wrote in the 1st comment:
Votes: 0
Hello:
In the code I inherited, there are newspaper's (which are a modification of the note code). Now, we have the ability to suppress newspaper articles, but I discovered after taking it over there it was not saving the suppression. For those who don't know what I mean, suppression is basically getting the article "buried" so it doesn't make the newspaper printing (like if you don't want people to know there are vampires and someone makes an articles about vampires). So, this is the code, but I can't seem to figure out why it's not saving the increase in difficulty.
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;
return TRUE;
}


Can anyone see something I'm missing? Thank you in advance.

Arholly
14 Oct, 2011, Rarva.Riendf wrote in the 2nd comment:
Votes: 0
Can your dice rolls accept and return negative value ? (if not, the second else is useless)
(and btw, the first else is useless as well as you return anyway)

because ch->influences[INFL_MEDIA]–; can become negative.

otherwise only thing changing in notes is pnote->successes += fail;

so the problem may be elsewhere in the display
14 Oct, 2011, arholly wrote in the 3rd comment:
Votes: 0
The dice rolls should not return a negative value. They might return a zero, but not a negative because the influence shouldn't be able to become negative, but I can see how it looks like it would.

Crud. Any thoughts on where I should look?
14 Oct, 2011, Rarva.Riendf wrote in the 4th comment:
Votes: 0
Ok you can remove the code in the last else then, it will never be called…(and your timer is only increased in case of a fail btw)

I suggest you look everywhere the field successes in pnote->successes += fail; is used
14 Oct, 2011, arholly wrote in the 5th comment:
Votes: 0
Ok, I was looking at where the immortal command for suppression is, not just the influence command and this is what pops up.
if ( !str_prefix( arg, "suppression" ))
{
if(type == NOTE_ARTICLE)
{
argument = one_argument(argument, arg2);
if ( !is_number( argument ) || !is_number( arg2 ) )
{
send_to_char(
"Which article's suppression are you trying to affect?\n\r",
ch );
send_to_char(
"And what number of successes are you setting it to?\n\r", ch);
send_to_char(
"(Use 0 for unsuppressed)\n\r", ch);
return;
}

anum = atoi( arg2 );

vnum = 0;
for ( pnote = *list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) && ( vnum++ == anum ) )
{
pnote->successes = atoi(argument);
send_to_char("Suppression level set.\n\r", ch);
return;
}
}

Now, where it says pnote->successes = atoi(argument);, that shold be pnote->successes = atoi(arg2); correct? Because it looks like arg2 is the suppression number.
14 Oct, 2011, Rarva.Riendf wrote in the 6th comment:
Votes: 0
No it is fine, problem not here (and you should really use a debbugger to set your breakpoint and see your variable values while running code.
one argument takes one parmaeter and retrn the rest

so arg2 is the article number, and arguement the last argument, so the nuber of successes
14 Oct, 2011, arholly wrote in the 7th comment:
Votes: 0
Ok, so the only time pnote->successes += fail; is used in the media_suppress.

So, I then went looking for pnote->successes, just to see what I can find.
I found it in save_notes, load_thread, append_note, note_attach, parse_note, media_promote (which makes suppressed articles available), and that's it. Any thoughts on which I should start looking at first?
14 Oct, 2011, plamzi wrote in the 8th comment:
Votes: 0
Do you have an in-game command like stat or vstat that shows the suppression level of a given article right after a success?

If the successes var is incremented in game but doesn't persist, I would look at "save_notes" first to see if it's properly stored, and then load_thread (which sounds like the loader function?). It could also be that "save_notes" is fine but doesn't get called in certain cases where it should? For instance, I would have expected to see it called inside the if(fail > 0) {} clause.
15 Oct, 2011, Rarva.Riendf wrote in the 9th comment:
Votes: 0
Just another question:what do you code with ? I think it would greatly help you if you had an IDE so you can follow variable value while the code is running.
Would save you a lot of questions.
I use Eclipse myself on both Windows (with cygwin) and Linux.
16 Oct, 2011, arholly wrote in the 10th comment:
Votes: 0
@plamzi:
It looks like it is incrementing, but not saving. But, the code makes it look like it is saving.
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 != 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);
}
fprintf( fp, "Success %d~\n", pnote->successes);
fprintf( fp, "Text\n%s~\n", pnote->text);
}
fclose( fp );
fpReserve = fopen( NULL_FILE, "r" );
return;
}
}


@Rarva.Riendf: I'm not sure what you are talking about. I use Notepad ++ for doing my coding. I'm guessing that Eclipse is something to help me with that? I'll look into it on Monday and probably have a ton of questions.
16 Oct, 2011, plamzi wrote in the 11th comment:
Votes: 0
When / where is save_notes called? It looks like it's saving all the notes in game, which explains why it's not called after every successful suppression. But maybe it's not being called often enough?
16 Oct, 2011, Rarva.Riendf wrote in the 12th comment:
Votes: 0
Eclipse is an IDE. Within it you can run the mud , edit all the files like you would with notepad++ and a lot more. You can also launch gdb , just click on a line of code and it will stops there. And you will see the value of the variable. You can simply click on a field and using reference would tell you where it is used.
It is quite easy to set up. Now I only suggested Eclipse cause I am used to it, and the config is almost the same on both linux and windows.
Notepadd++ is a great text editing tool, but not the best tool to code.

and for your problem : fprintf( fp, "Success %d~\n", pnote->successes); so the sucesses is saved, and the notes as well, whatever the value of it.
The only thing left is that when you display the notes, you just ignore the field so notes are displayed, buried or not.
17 Oct, 2011, arholly wrote in the 13th comment:
Votes: 0
OK, save_notes is only found in olc.c. It's only found in two functions, note_remove and our knowledge/background editor (which uses the same note functions as articles). So, I'm guessing it's like plamzi said and it's not saving the suppression when they are made.

So, can I solve it by adding save_notes(pnote->type); at the end of the media suppression functions to force it to save?
17 Oct, 2011, Rarva.Riendf wrote in the 14th comment:
Votes: 0
arholly said:
OK, save_notes is only found in olc.c. It's only found in two functions, note_remove and our knowledge/background editor (which uses the same note functions as articles). So, I'm guessing it's like plamzi said and it's not saving the suppression when they are made.

So, can I solve it by adding save_notes(pnote->type); at the end of the media suppression functions to force it to save?

Nod. would be a start. If it stills show, try to check the display method, it may ignore the successes field anyway.
17 Oct, 2011, arholly wrote in the 15th comment:
Votes: 0
OK, Rarva, I'll do that.
I have a question about eclipse though. It's telling me I don't have an all in my makefile. What the heck is talking about?
CC      = gcc
PROF = -O -Wuninitialized
NOCRYPT =
C_FLAGS = -Wall -g $(PROF) $(NOCRYPT)
L_FLAGS = $(PROF)

O_FILES = act_comm.o act_enter.o act_info.o act_move.o act_obj.o act_wiz.o \
alias.o comm.o const.o db.o fight.o subcmds.o\
handler.o interp.o lookup.o magic.o fight_old.o\
recycle.o save.o tables.o update.o olc.o\
olc_act.o olc_save.o string.o quest.o magic3.o\
mob_cmds.o mob_prog.o olc_mpcode.o social-edit.o

O_TESTFILES = act_comm.o act_enter.o act_info.o act_move.o act_obj.o act_wiz.o \
alias.o comm.o const.o db.o fight.o subcmds.o\
handler.o interp.o lookup.o magic.o fight_old.o\
recycle.o save.o tables.o update.o olc.o\
olc_act.o olc_save.o string.o quest.o magic3.o\
mob_cmds.o mob_prog.o olc_mpcode.o social-edit.o

pt: $(O_FILES)
rm -f project
rm -f project.exe
$(CC) $(L_FLAGS) -lm -o project $(O_FILES)

test: $(O_TESTFILES)
rm -f projecttest
rm -f projecttest.exe
$(CC) $(L_FLAGS) -lm -o projecttest $(O_TESTFILES)

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

clean:
rm *.o

wipe:
rm -f *.o project
rm -f project.exe
rm -f projecttest
rm -f projecttest.exe

How do I get it setup so it'll work. My makefile is named makefile, but it looks like it is asking for me to change something in the Makefile.
17 Oct, 2011, arholly wrote in the 16th comment:
Votes: 0
Errr…OK, I added save_notes(pnote->type); into the media_suppress function, made, rebooted, suppressed an article and it displayed fine. Rebooted to see if it saved and it didn't. I'm really at a loss now. I even added something to make sure I could see the suppression level, which before I couldn't.
if(type == NOTE_ARTICLE) {
sprintf( buf, "[%3d] %s: %s\n\r%s\n\rCategory: %s\n\rSuppression Level: %d\n\r",
vnum -1,
pnote->sender,
pnote->subject,
pnote->date,
pnote->to_list,
pnote->successes);

And it shows the successes being incremented whenever I successfully suppress an article, it's just not saving across reboots.

Any more thoughts?
17 Oct, 2011, plamzi wrote in the 17th comment:
Votes: 0
Try adding this:

all: $(O_FILES)
$(CC) $(L_FLAGS) -lm -o project $(O_FILES)
17 Oct, 2011, arholly wrote in the 18th comment:
Votes: 0
Thanks.
17 Oct, 2011, arholly wrote in the 19th comment:
Votes: 0
Wow…Lots of warnings…
17 Oct, 2011, arholly wrote in the 20th comment:
Votes: 0
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.
0.0/41