Original Post
Ok, so I've got this nice program that I'm building slowly and surely and once again, something I wrote that I believe should work, isn't and I need your help again Gamedev.net. NOW, I'll try to explain this better than I usually do. First, I thought I'll need to create a function that can be called in my game that will get an item's information from the database file, this way I won't have to hardcode each and every item in the game into the source files, which we all know is a boneheaded thing to do right? Here's the problem: The function I wrote is not working:
void Item::GetItemInfo(string itemName, Item &item)
{
ifstream fin;
string tmpFilename = "C:/Game/Items/MasterItemList.lis";
fin.open(tmpFilename.c_str());
string szNameIn;
string szWord;
string filename;
bool bLoaded = false;
while(!bLoaded)
{
if(fin.fail())
{
cout << "File Input Failed!"
<< endl
<< "Find out why!"
<< endl;
}
// Here is where I believe the problem is. The Master Item List
// contains the name and the location of each item file, like so
/*
Item: ItemName
Location: C:/GameFolder/Items/ItemName.itm
Item: ItemName2
Location: C:/You Get The picture/ItemName2.itm
*/
// The function I wrote that is supposed to create items and
// Their .itm file works. It even updates the Master Item List
// So the problem isn't there.
// Read in one word at a time, one line at a time
fin >> szWord >> szNameIn;
// Read in one word at a time, one line at a time
fin >> szWord >> filename;
// Read in the next blank line
fin >> szWord;
// If this next part checks to be FALSE, shouldn't it keep
// checking till it hits the end of the file?
if(szNameIn == itemName)
{
// Go open the new file.
fin.close();
string szWord = "NULL";
string tmpLabel = "NULL";
int tmpNum = 0;
fin.open(filename.c_str());
fin.seekg(NULL, ios::beg);
fin >> szWord;
fin >> szWord;
fin >> tmpLabel;
item.SetItemName(tmpLabel);
fin >> szWord >> szWord >> tmpLabel;
item.SetItemType(tmpLabel);
cout << "Item Loaded." << endl;
Sleep(1000);
bLoaded = true;
}
else
cout << "Item Name not Found.";
Sleep(1000);
break;
}
system("cls");
} // End of GetItemInfo()