Posted by
| Zeno
USA (2,871 posts) bio
|
Message
| Alright, I've got the character struct working, so now I'm trying to link a skill/attack struct to the character struct.
In the load_character function:
case 'A':
SREAD( "Attack0", character->attacks[0]->name );
Reads an attack file:
ATTACK *load_attack(char *argument)
{
FILE *fp;
ATTACK *attack = NULL;
char afile[256];
char aName[20];
int size, i;
char *word;
bool done = FALSE, found;
aName[0] = toupper(argument[0]);
size = strlen(argument);
for (i = 1; i < size; i++)
aName[i] = tolower(argument[i]);
aName[i] = '\0';
sprintf(afile, "../attacks/%s.atk", aName);
if ((fp = fopen(afile, "r")) == NULL)
return NULL;
if ((attack = malloc(sizeof(*attack))) == NULL)
{
bug("Load_attack: Cannot allocate memory.");
abort();
}
word = fread_word(fp);
while (!done)
{
found = FALSE;
switch (word[0])
{
case 'C':
SREAD( "Cmd", attack->cmd );
break;
case 'N':
SREAD( "Name", attack->name );
break;
case 'P':
SREAD( "PreAttack", attack->preattack );
break;
case 'E':
if (compares(word, "EOF")) {done = TRUE; found = TRUE; break;}
break;
}
if (!found)
{
bug("Load_attack: unexpected '%s' in %s's afile.", word, argument);
return NULL;
}
if (!done) word = fread_word(fp);
}
fclose(fp);
return attack;
}
main.h
typedef struct attack_data ATTACK;
In char struct:
struct attack_data
{
char * name;
char * cmd;
char * preattack;
};
Attack part of a char:
The struct for attacks work, I can display the file in a cmd.
But when loading a char with an attack, it crashes, with this debug:
#0 0x0804edee in load_character (argument=0x805aae1 "cloud") at save.c:307
#1 0x0804d8f4 in cmd_showchar (dMob=0x805b0a0, arg=0x811db58 "Slash") at commands.c:706
#2 0x0804b823 in handle_cmd_input (dsock=0x811db58, arg=0x805aae1 "cloud") at interpret.c:33
#3 0x0804943f in game_loop (control=3) at socket.c:175
#4 0x0804925c in main (argc=3, argv=0xbffff954) at socket.c:77
#5 0x42015967 in __libc_start_main () from /lib/i686/libc.so.6
The character loads fine until it gets to attack.
302 {
303 found = FALSE;
304 switch (word[0])
305 {
306 case 'A':
307 SREAD( "Attack0", character->attacks[0]->name );
308 SREAD( "AfterAKill1", character->afterakill1 );
309 break;
310 case 'B':
311 SREAD( "BlockFail", character->blockfail );
character->attacks[0] is not loading, because its null.
Why is it not reading correctly? |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | top |
|