06 Mar, 2008, Kline wrote in the 41st comment:
Votes: 0
@DavidHaley: Thanks, made quick use of that :)

Here's the highlights, my full log is playing with BP's is available at http://games.gotr00t.us/vortex/files/gdb...

Lines in reference:
(gdb) list
1762 if( arg1[0] == '\0' )
1763 {
1764 act2("$D",ch,NULL,NULL,TO_CHAR,statcap);
1765 statcap = 54321;
1766 sprintf(buf,"You have %d experience points and a %d statcap.\n\r",ch->exp,statcap);
1767 stc(buf,ch);
1768 act2("$D",ch,NULL,NULL,TO_CHAR,statcap);
1769 sprintf(arg1,"foo");
1770 }


BP Output:
Breakpoint 3, train (ch=0x8fa0330, argument=0x903fcbc "") at movelib.c:1762
1762 if( arg1[0] == '\0' )
(gdb) p statcap
$10 = 30125
1764 act2("$D",ch,NULL,NULL,TO_CHAR,statcap);
(gdb) p statcap
$11 = 30125
1765 statcap = 54321;
(gdb) p statcap
$12 = 30125
1766 sprintf(buf,"You have %d experience points and a %d statcap.\n\r",ch->exp,statcap);
(gdb) p statcap
$13 = 54321
1767 stc(buf,ch);
(gdb) p statcap
$14 = 54321
1768 act2("$D",ch,NULL,NULL,TO_CHAR,statcap);
(gdb) p statcap
$15 = 54321


So the value is changing properly…So should I be looking at the contents of the buffer itself? Or is it already known, due to the in-game output?
06 Mar, 2008, David Haley wrote in the 42nd comment:
Votes: 0
Indeed it looks like there's nothing wrong with statcap. Yeah, printing out the contents of 'buf' looks like a reasonable next step to me. Try before and after the sprintf statement.
06 Mar, 2008, Kline wrote in the 43rd comment:
Votes: 0
Here's the results, going to see if clearing the buf first makes any difference…But I've never run into a situation (yet) where it would.

Breakpoint 1, train (ch=0x8c46e20, argument=0x8c460b4 "") at movelib.c:1765
1765 statcap = 54321;
(gdb) print buf
$1 = long string of garbage data
1766 sprintf(buf,"You have %d experience points and a %d statcap.\n\r",ch->exp,statcap);
(gdb) print buf
$2 = long string of garbage data
1767 stc(buf,ch);
(gdb) print buf
$4 = "You have 1515898647 experience points and a 0 statcap.\n\r*LONG STRING OF GARBAGE DATA*"


Interestingly enough I just tried rolling the variable order (ch->exp,statcap) to (statcap,ch->exp) and it works fine like that. I really don't have any heartburn about re-arranging it permenantly like that, as admittedly I find it more aesthetically appealing…But I'm still curious as to why this is happening :P
06 Mar, 2008, Zeno wrote in the 44th comment:
Votes: 0
Zeno said:
Have you tried this in other functions?

Have you tried this in a brand new c file with a new exec (nothing to do with the MUD)?


If it only happens in this fn, I wouldn't suggest using it. It's messy, too. :P
06 Mar, 2008, drrck wrote in the 45th comment:
Votes: 0
Try using snprintf() instead of sprintf(). Really, you should be doing that anyway.
07 Mar, 2008, Remcon wrote in the 46th comment:
Votes: 0
Quote
Interestingly enough I just tried rolling the variable order (ch->exp,statcap) to (statcap,ch->exp) and it works fine like that. I really don't have any heartburn about re-arranging it permenantly like that, as admittedly I find it more aesthetically appealing…But I'm still curious as to why this is happening :P

Ok so if you change
sprintf(buf,"You have %d experience points and a %d statcap.\n\r",ch->exp,statcap);

to this
snprintf( buf, sizeof( buf ), "You have a statcap of %d and %d experience points.\r\n", statcap, ch->exp );

it works fine yet it doesn't work the other way….That has to be an odd issue there. (Btw notice that i did \r\n shrug it was said long ago that is how it should be, I also used snprintf since it should be used when possible.)

I can't think of any reason right off that would cause it to work one way and not the other, but you never know lol. Try adding other int displays etc… and see if you can't narrow down what will and won't work correctly to maybe give someone some idea on the issue.
07 Mar, 2008, David Haley wrote in the 47th comment:
Votes: 0
Thing is, you changed three things at once there Remcon: you changed the order of the variables and from sprintf to snprintf, and you switched the line endings. It's true that it doesn't make sense for the order of parameters to matter, but to best isolate this we should try to control the situation as precisely as possible. We should make just one change at a time, otherwise it won't be clear which of the three changes fixed it.

What if you use snprintf with the parameters in the right order?
09 Mar, 2008, Kline wrote in the 48th comment:
Votes: 0
snprintf(buf,sizeof(buf),"You have %d experience points and a %d statcap.\n\r",ch->exp,statcap);

Still outputs You have 1515898647 experience points and a 0 statcap.
09 Mar, 2008, Guest wrote in the 49th comment:
Votes: 0
And what happens when you reverse the order of the variables at the end of that function call?
25 Mar, 2008, Kline wrote in the 50th comment:
Votes: 0
Sorry, again, a big gap in my posting. Back home from the business trip now though so hopefully life is a bit more stable :)

Samson, the answer to your question (reversed vars) works fine:
snprintf(buf,sizeof(buf),"You have %d experience points and a %d statcap.\n\r",statcap,ch->exp);
40.0/50