05 Apr, 2009, Zula wrote in the 1st comment:
Votes: 0
Alright, I am trying to do my own spell system and somehow the name of the spell keeps changing to END
I put some bug()'s in to print it's value at various points and it shows 'fireball' all the way up to where I add my SPELL_DATA to the characters list, but then when I log on with a test char and type spells
it outputs that the name is END(And its not the 'End' in the playerfile because it's not all caps. The playerfile has this line:
Sp 'fire damage' 1 1 2 10 1 8 1 'fireball'

And in the load there is:
if (!str_cmp (word, "Spell") || !str_cmp (word, "Sp"))
{
SPELL_DATA *spd;
char *tmp_buf;
sh_int efn;
tmp_buf = fread_word(fp);
efn = effect_lookup(tmp_buf);

spd = new_spell();
spd->school = fread_number(fp);
spd->target = fread_number(fp);
spd->min_val = fread_number(fp);
spd->max_val = fread_number(fp);
spd->duration = fread_number(fp);
spd->minimum_position = fread_number(fp);
spd->beats = fread_number(fp);
tmp_buf = fread_word(fp);
bug("Save.c", 0);
bug(tmp_buf, 0);
spd->name = tmp_buf;
bug(spd->name, 0);
spd->effect_number = efn;
spell_to_char(ch, spd);
bug("Back in Save.c", 0);
bug(spd->name, 0);
fMatch = TRUE;
}

And that calls spell_to_char in handler which looks like this
void spell_to_char (CHAR_DATA * ch, SPELL_DATA * psd)
{
SPELL_DATA *psd_new;

psd_new = new_spell();

*psd_new = *psd;

VALIDATE(psd);

psd_new->next = ch->first_spell;
ch->first_spell = psd_new;
bug("Handler.c", 0);
bug(psd_new->name, 0);
bug(ch->first_spell->name, 0);
return;
}


And the log those bugs leave is:
Sun Apr  5 17:35:31 2009 :: Loading Tester.
Sun Apr 5 17:35:31 2009 :: [*****] BUG: Save.c
Sun Apr 5 17:35:31 2009 :: [*****] BUG: fireball
Sun Apr 5 17:35:31 2009 :: [*****] BUG: fireball
Sun Apr 5 17:35:31 2009 :: [*****] BUG: Handler.c
Sun Apr 5 17:35:31 2009 :: [*****] BUG: fireball
Sun Apr 5 17:35:31 2009 :: [*****] BUG: fireball
Sun Apr 5 17:35:31 2009 :: [*****] BUG: Back in Save.c
Sun Apr 5 17:35:31 2009 :: [*****] BUG: fireball
06 Apr, 2009, Zula wrote in the 2nd comment:
Votes: 0
Oh yeah, before anyone asks for it, here is my do_spells….
void do_spells (CHAR_DATA *ch, char *argument)
{
char output[MSL];
bool found;
char buf[MSL];
SPELL_DATA *psd;

if(IS_NPC(ch))
return;
output[0] = '\0';
found = FALSE;
psd = ch->first_spell;
while(psd!=NULL) {
found = TRUE;
sprintf(buf, "%s: %s %d to %d for %d.\n\r", psd->name,
spell_table[psd->effect_number].name, psd->min_val,
psd->max_val, psd->duration);
strcat(output, buf);
psd = psd->next;
}
if(!found) {
send_to_char("No spells found.\n\r", ch);
return;
}
send_to_char("Spells:\n\r", ch);
send_to_char(output, ch);
}

it is psd-name that is being printed as END
Spells:
END: fire damage 2 to 10 for 1.
06 Apr, 2009, David Haley wrote in the 3rd comment:
Votes: 0
If memory serves, fread_word uses a static buffer, so you need to actually copy the result from the function instead of just assigning the pointer.
06 Apr, 2009, Zula wrote in the 4th comment:
Votes: 0
Yep, that was it, adding str_dup fixed 'er right up, Thanks man :biggrin:
06 Apr, 2009, David Haley wrote in the 5th comment:
Votes: 0
Make sure you use the right pair of allocate/free functions; if these are freed using DESTROY then you're fine with strdup, but if they're freed using the hashed string function (STRFREE) you need to use the hashed string allocation (STRALLOC).
0.0/5