03 Aug, 2010, jurdendurden wrote in the 1st comment:
Votes: 0
I've created a command in OLC called QEdit, for making quests on the fly. I'm having trouble getting it to save. I can create a new quest fine, edit values within that quest, etc… but when I asave changed/asave world, the quest is no longer there, it never saves to the area file… I have combed the code and cannot find my error, so here are a few related functions, if anyone has any ideas feel free :)

db.c:
QUEST_DATA *get_quest_index (int vnum)
{
QUEST_DATA *pQuest;

for (pQuest = quest_index_hash[vnum % MAX_KEY_HASH];
pQuest != NULL; pQuest = pQuest->next)
{
if (pQuest->index == vnum)
return pQuest;
}

if (fBootDb)
{
bug ("Get_quest_index: bad vnum %d.", vnum);
exit (1);
}

return NULL;
}


olc_save.c:
void save_quests (FILE * fp, AREA_DATA *pArea)
{
int i = 0;
QUEST_DATA *pQuest;

fprintf (fp, "#QUESTS\n");

for (i = pArea->min_vnum; i <= pArea->max_vnum; i++)
{
if ((pQuest = get_quest_index(i)))
save_quest (fp, pQuest);
}

fprintf (fp, "#0\n\n\n\n");
return;
}

void save_quest ( FILE * fp, QUEST_DATA * pQuest )
{
fprintf (fp, "#%d\n", pQuest->index);
fprintf (fp, "%s~\n", pQuest->name);
fprintf (fp, "%d\n", pQuest->level);
fprintf (fp, "%ld\n", pQuest->accept_vnum);
fprintf (fp, "%ld\n", pQuest->return_vnum);

return;
}


I get no errors whatsoever so I'm not sure what's going on. Again any assistance would be great.
03 Aug, 2010, JohnnyStarr wrote in the 2nd comment:
Votes: 0
Are you sure that save_quests is being called on save? I would break point it in gdb and make sure this function is even being called. It's probably just one line somewhere in there.
03 Aug, 2010, Sharmair wrote in the 3rd comment:
Votes: 0
You did not give enough code to really figure out what is going on. But from seeing this code,
the first thing I would do is actually look at an area file and see if the #QUESTS section is there.
If it is NOT there, then you are not calling your save_quests function from your area save
function. If it is there, but empty, then I would make sure the area's vnums are set right. But
at this point it could be a number of things that I would have to see more code for. If you do
find the quest section is written correctly, then start looking in the loading code to make sure
the load area function is handling the #QUESTS section, and putting the quests in the hash table.
Though again, I would have to see more code.
03 Aug, 2010, jurdendurden wrote in the 4th comment:
Votes: 0
I'm sorry you're right I should have mentioned that. #QUESTS is showing up in each area file, so it's being called, and as you have pointed out (and I have suspected), it's possibly an issue with the hash table… I've tried manually inserting a quest into an area file, and i'm just getting the 'Get_quest_index: bad vnum 1000.' as seen in the above get_quest_index function. Here is the load_quests function as well, what other code would you need to look at?

void load_quests (FILE * fp)
{
QUEST_DATA *pQuest;
bool fBootDb;
int iHash;

if (!area_last)
{
bug ("Load_quests: no #AREA seen yet.", 0);
exit (1);
}

for (;;)
{
int vnum = 0;
char letter;

letter = fread_letter (fp);
if (letter != '#')
{
bug ("Load_quests: # not found.", 0);
exit (1);
}

vnum = fread_number (fp);
if (vnum == 0)
break;

fBootDb = FALSE;
if (get_quest_index (vnum) != NULL)
{
bug ("Load_quests: vnum %d duplicated.", vnum);
exit (1);
}
fBootDb = TRUE;

pQuest = alloc_perm (sizeof (*pQuest));
pQuest->index = vnum;


pQuest->area = area_last;
pQuest->name = fread_string ( fp );
pQuest->level = fread_number ( fp );
pQuest->accept_vnum = fread_number ( fp );
pQuest->return_vnum = fread_number ( fp );

iHash = vnum % MAX_KEY_HASH;
pQuest->next = quest_index_hash[iHash];
quest_index_hash[iHash] = pQuest;
top_quest_index++;
top_vnum_quest = top_vnum_quest < vnum ? vnum : top_vnum_quest; /* OLC */
assign_area_vnum (vnum); /* OLC */
}
log_f("Loaded %d quests.", top_quest_index);
return;

}
03 Aug, 2010, JohnnyStarr wrote in the 5th comment:
Votes: 0
Jurden, it seems as though your OLC is assigning an invalid vnum. What I would do, is manually enter a quest and respective
members into your .are file manually with a text editor. Boot up, and assess whether or not it is the loading routine, or the OLC.
03 Aug, 2010, Sharmair wrote in the 6th comment:
Votes: 0
jurdendurden said:
I've tried manually inserting a quest into an area file, and i'm just getting the 'Get_quest_index: bad vnum 1000.' as seen in the above get_quest_index function.

From the code for the load, this would be because the quest does not exist at the time you are calling the
get_quest_index function, and would actually never work. You have defined a local fBootDb that shadows
the global fBoolDb. To clarify, you are setting your local fBootDb to FALSE before the call to check for
duplicates, but get_quest_index is still looking at the global fBootDb that is still TRUE, so it bails before
you ever get to the real quest loading. You should remove that bool fBootDB; at the top of the function.

I would see if the manual editing of the area files gets you a valid quest, if so it pretty much points to the
OLC. Then more of that code would be in order.
03 Aug, 2010, jurdendurden wrote in the 7th comment:
Votes: 0
Ok so I have since gotten it to work, and here was the problem:

iHash = value % MAX_KEY_HASH;
pQuest->next = quest_index_hash[iHash];


Should have been:

iHash = value % MAX_KEY_HASH;
pQuest->next = quest_index_hash[iHash];
quest_index_hash[iHash] = pQuest;


Thanks all for the help!
0.0/7