15 Jun, 2009, boblinski wrote in the 1st comment:
Votes: 0
Okay, I'm trying to add a new stat charisma (CHR) to my mud (QuickMUD src).

I did a file search for STAT_CON and APPLY_CON etc and found where I had to put things.. I was relatively happy about how well it was going.. and it compiled without errors..

BUT.. when I log onto the mud..
- It asks me "Do you want ANSI? (Y/n)" and I type "Y"… that's fine..
- Then is asks "By what name are you known?" and I type "Bob"… And the mud crashes..

I was running it in GDB using Cygwin.. this is the output I get upon entering "bob"–>

Quote
Mon Jun 15 13:23:30 2009 :: Loading Bob.
Mon Jun 15 13:23:30 2009 :: [*****] BUG: Fread_char: no match.
Mon Jun 15 13:23:30 2009 :: [*****] BUG: 3
Mon Jun 15 13:23:30 2009 :: [*****] BUG: Fread_char: no match.
Mon Jun 15 13:23:30 2009 :: [*****] BUG: 2047

Program received signal SIGSEGV, Segmentation fault.
skill_lookup (name=0x64 <Address 0x64 out of bounds>) at magic.c:70
70 if (LOWER (name[0]) == LOWER (skill_table[sn].name[0])
(gdb)


I have no idea why it is saying magic.c line 70.. never editted anything in magic.c… this the the segment of code anyhow:
int skill_lookup (const char *name)
{
int sn;

for (sn = 0; sn < MAX_SKILL; sn++)
{
if (skill_table[sn].name == NULL)
break;
if (LOWER (name[0]) == LOWER (skill_table[sn].name[0]) /* line 70 */
&& !str_prefix (name, skill_table[sn].name))
return sn;
}

return -1;
}


Any ideas? Just yell out if you need to see more code..
15 Jun, 2009, Sharmair wrote in the 2nd comment:
Votes: 0
When you added this new (for you) stat, did you write the code for loading the stats on the
character in a way that would handle old player files without the new stat? Though I am a bit
amazed that you went as far as the skill load on the character before things were out of sync
enough to crash (and only had two character loading bugs), it does look like the player file
is not formatted the way the loading code is expecting. The fact that there are numbers where
the loading code is expecting tag names also points to the pfile being out of sync (it could be
corrupted too, but being you just added something else and it really is quite common for MUD
coders to mess up on backwards compatibility, I would look at how you are formatting the
pfile first).
15 Jun, 2009, Kline wrote in the 3rd comment:
Votes: 0
Hopefully you version your pfiles.
if( new_pfile_version )
load_new_stat();
15 Jun, 2009, boblinski wrote in the 4th comment:
Votes: 0
Sharmair said:
did you write the code for loading the stats on the character in a way that would handle old player files without the new stat?

I believe not.. I simply copied from what was already in the code for the stat CON.

Sharmair said:
I would look at how you are formatting the pfile first

What part of the code should I be looking at?

Kline said:
Hopefully you version your pfiles.
if( new_pfile_version )
load_new_stat();

No I've never done this.. could someone explain a little more about version-ing pfiles?
15 Jun, 2009, boblinski wrote in the 5th comment:
Votes: 0
I went to save.c and in fwrite_char I changed:
fprintf (fp, "Attr %d %d %d %d %d %d\n",
ch->perm_stat[STAT_STR],
ch->perm_stat[STAT_INT],
ch->perm_stat[STAT_WIS],
ch->perm_stat[STAT_DEX],
ch->perm_stat[STAT_CON],
ch->perm_stat[STAT_CHR]); //CHR

fprintf (fp, "AMod %d %d %d %d %d %d\n",
ch->mod_stat[STAT_STR],
ch->mod_stat[STAT_INT],
ch->mod_stat[STAT_WIS],
ch->mod_stat[STAT_DEX],
ch->mod_stat[STAT_CON],
ch->mod_stat[STAT_CHR]); //CHR


TO–>
fprintf (fp, "Attr %d %d %d %d %d %d\n",
ch->perm_stat[STAT_STR],
ch->perm_stat[STAT_INT],
ch->perm_stat[STAT_WIS],
ch->perm_stat[STAT_DEX],
ch->perm_stat[STAT_CON], ch->perm_stat[STAT_CHR]); //CHR

fprintf (fp, "AMod %d %d %d %d %d %d\n",
ch->mod_stat[STAT_STR],
ch->mod_stat[STAT_INT],
ch->mod_stat[STAT_WIS],
ch->mod_stat[STAT_DEX],
ch->mod_stat[STAT_CON], ch->mod_stat[STAT_CHR]); //CHR


I can now log in and create a -new- character.. but if I try to log in with an existing character.. the mud crashes unless I go in and change the pfile manually.

I have three questions:
1) Is this change in fwrite_char the correct fix?
2) If it is the correct fix.. what is the difference between the two (why does one work but not the other) ?
3) How do I make the pfile change automatically?
15 Jun, 2009, Omega wrote in the 6th comment:
Votes: 0
did you increase MAX_STATS.

Your old save-format won't work loading like that either, so if you updating the loading
if ( !str_cmp( word, "AttrMod"  ) || !str_cmp(word,"AMod"))
{
int stat;
for (stat = 0; stat < MAX_STATS; stat ++)
ch->mod_stat[stat] = fread_number(fp);
fMatch = TRUE;
break;
}


becuase of that, there, it will look for the extra-stat, and not exist. There ending your loading process, as there will be an extra fread_number called, and it won't necessarily be on a number ;)

my recommendation is to use something like.

if ( !str_cmp( word, "AttrMod"  ) || !str_cmp(word,"AMod"))
{
int stat;
if(ch->version <= 3) {
for (stat = 0; stat < 5; stat ++)
ch->mod_stat[stat] = fread_number(fp);
} else {
for (stat = 0; stat < MAX_STATS; stat ++)
ch->mod_stat[stat] = fread_number(fp);
}
fMatch = TRUE;
break;
}


Since it looks like your using rom, rom comes stock with pfile version support, so you can use that very easily.

At the top of fwrite_char, you will see a line like:

fprintf( fp, "Vers %d\n",   3			);


Simply change the version number to, say, 4 ;) one higher then what it is. And the changed load routine that I posted. And your pfiles should load, and save properly.

I know it works for me :)
19 Jun, 2009, boblinski wrote in the 7th comment:
Votes: 0
I'm trying to Add "ETHOS" to my mud.. I've got it working on PCs.. and am now trying to add it to NPCs..
I can get it to compile but when I try to boot-up.. I get this:

Quote
$ ../src/rom 8888
Sat Jun 20 09:45:37 2009 :: Loading configuration settings from ../area/qmconfig.rc.
Sat Jun 20 09:45:37 2009 :: Set IP address to 0.0.0.0
Sat Jun 20 09:45:37 2009 :: Loaded 0 mobprogs.
Sat Jun 20 09:45:37 2009 :: [*****] FILE: operate.are LINE: 21
Sat Jun 20 09:45:37 2009 :: [*****] BUG: Fread_number: bad format.


I think it's just that the format of my mobiles has now changed (due to adding ethos right after alignment).

Is there a "version" type thing for area files? Or something I can do that says… -if the mob doesn't have a number for ethos… put '0'- ?

Hopefully that's not too hard to understand. :lol:
19 Jun, 2009, Kline wrote in the 8th comment:
Votes: 0
Version for areas: yes, probably. You'd have to check your specific code.
If no ethos = 0: Yes and no. You can initialize (and should) your ethos to a default value, say 0 for instance, and just overwrite the default when you load the MOB. The way fread_xyz() functions in Diku games tend to work is they expect to find certain data there. So you can't really (easily) check "does the file have this data? yes -> read : no -> default" without versioning your areas as a whole.
20 Jun, 2009, boblinski wrote in the 9th comment:
Votes: 0
So will this initialization fix my problem do you think?

Where do I initialize?
20 Jun, 2009, Sandi wrote in the 10th comment:
Votes: 0
ROM doesn't save stats for mobs, which might explain why you're having trouble loading them.
20 Jun, 2009, boblinski wrote in the 11th comment:
Votes: 0
Sandi said:
ROM doesn't save stats for mobs, which might explain why you're having trouble loading them.

Sorry, I guess I should have started a new topic, but I'm actually having trouble with my "Ethos" now.
20 Jun, 2009, Sandi wrote in the 12th comment:
Votes: 0
Oh, sorry, a quick scan made me think it was a stat.

Initialise in merc.h when you declare it.

Seems to me there should be a way to do a global save of all your areas that would add this to every mob. Then, they should load okay.
20 Jun, 2009, boblinski wrote in the 13th comment:
Votes: 0
struct    mob_index_data
{
sh_int ethos = 0;
etc
etc
}


Will this not mean it will reset to 0 every time I boot up?

Also.. should I set it to "= 0" in struct char_data ?
20 Jun, 2009, Kline wrote in the 14th comment:
Votes: 0
No, it won't. You need to set each of your mobIndexData->ethos = 0 when you load up areas.

Quote
Also.. should I set it to "= 0" in struct char_data ?

No, see above. You would need to initialize it as you create mobs/players. Also, see below, prior to my edit, on how to access your ethos value.

That depends, how do you want to access it? If you are comfortable with if( IS_NPC(ch) && ch->pMobIndex->ethos == xyz ) then you don't need it in your char_data. If, however, you'd like to either a) have it on players, too, or b) access it via ch->ethos, then yes, you do need it in char_data and will have to make the char_data copy the value from the IndexData as mobs are created.

edit: clarification
20 Jun, 2009, Hades_Kane wrote in the 15th comment:
Votes: 0
The way I go about adding new values in mobs is this, in a nut shell:

I add everything to the struct within merc.h and everywhere else that is needs it except in the loading. Make sure you have it to where it will save the values. Then after you reboot or copyover, do an asave world (and the new value is now saved into your area files) THEN you add the values to the loading part, compile and copyover, and everything should work fine.
0.0/15