Age... and Segmentation Fault

Posted by Raeyu on Thu 15 May 2003 10:16 AM — 2 posts, 13,453 views.

#0
I'm trying to add customizable age, like "age 20" to set your age, and I've gotten it so far, by uh, copying the icq command in the finger file, and doing some other stuff my friends suggested, but it came out like crap and now you can only set your age higher than 60 ONCE, no less, and when you type age to see your current age, it comes out like 5840 for 90, and if you set 60, it comes out like 41.. That, and it won't write it to the pfile, like the icq command does.. Here's the crapped out code:

void do_age( CHAR_DATA *ch, char *argument )
{
int age;

if ( IS_NPC( ch ) )
return;

if ( argument[0] == '\0' )
{
if ( !ch->pcdata->age )
ch->pcdata->age = 5;
ch_printf( ch, "Your age is: %o\n\r", ch->pcdata->age );
return;
}

if ( !is_number( argument ) )
{
send_to_char( "You must enter numeric data.\n\r", ch );
return;
}

age = atoi( argument );

if ( age < 5 )
{
send_to_char( "Valid range is 4-90.\n\r", ch );
return;
}

if ( age > 90 )
{
send_to_char( "Valid range is 4-90.\n\r", ch );
return;
}


ch->pcdata->age = age;

if ( IS_IMMORTAL( ch ) );
{
save_char_obj( ch );
build_wizinfo( FALSE );
}

send_to_char( "Age set.\n\r", ch );
return;
}
Australia #1
A few things..

1. "Your age is %o\n\r" should be "Your age is %d\n\r". The %o means octal.

2. You need to remove the ; from: if (IS_IMMORTAL(ch)); and possibly put the save_char_obj() outside of the if, so not just immortals are saved.

3. The reason it's not saving on the pfile is probably because you need to also add relevant code to save.c, probably in fread_char() and fwrite_char() (I hope they're the functions, I've never used SMAUG).

4. If the valid range is 4-90, then you need to use if (age < 4) not < 5.