This is really, really odd. For a game I'm working on, I'm trying to load the attributes of rooms, items, etc. from a file. I get a very, very strange problem during my loading process.
I've done some testing and it appears that once it reads in a certain number of characters, everything goes wrong.
I get this from my debug code: (ç is actually capitalized, but I can't find a capital version of it)
ID: 2
NAME: buckler
DESC: This round, iron shield is dented and rusted.
ID: 3
NAME: gate
DESC: The gate is çS= oor condition. It looks hastily built.
ID: 4
*CRASHES HERE*
Here's the part of my loading code that crashes. Before this, the program loads the information for the rooms in the game. The odd part is that if I comment out the bolded line below, it works FINE. I'm dumbfounded, because all that line does is set the description of the item! I also underlined the line that causes the error.
Before the loop, I declared "string input" and "int id". itemID is a temporary local array of Item pointers that I use to load my items in (so I can hang onto them while putting them in rooms).
Code:
//LOAD ITEMS
for(int i = 0; i < numItems; i++){
io >> id;
cout << "ID: " << id << endl; //DEBUG
io.ignore();
getline(io, input);
cout << "NAME: " << input << endl; //DEBUG
itemID[i]->setName(input);
getline(io, input);
cout << "DESC: " << input << endl; //DEBUG
itemID[i]->setDesc(input);
io >> intInput;
itemID[i]->setGetable(intInput);
io >> intInput;
itemID[i]->setUsable(intInput);
io >> intInput;
itemID[i]->setCharges(intInput);
io >> intInput;
itemID[i]->setDestroyOnDeplete(intInput);
io >> intInput;
itemID[i]->setOpenStatus(intInput);
io >> intInput;
itemID[i]->setGoDest1(intInput);
io >> intInput;
itemID[i]->setGoDest2(intInput);
io >> intInput;
itemID[i]->setEquippable(intInput);
io >> intInput;
itemID[i]->setDoor(intInput);
}
Here's the function that sets the description of the item.
Code:
void Item::setDesc(string newDesc)
{
desc = newDesc;
}
And finally, here's the half of the data file I'm loading from that the for loop sees. The top half of the file has the room data.
5
0
letter
A letter from General Isendol giving you command over the outpost. It is stamped with the royal military seal.
1 0 0 0 -1 -1 -1 0 0
1
spear
A basic wooden shaft with a blade for a head.
1 0 0 0 -1 -1 -1 1 0
2
buckler
This round, iron shield is dented and rusted.
1 0 0 0 -1 -1 -1 1 0
3
gate
The gate is in poor condition. It look hastily built.
0 0 0 0 0 7 3 0 1
4
post
A human skull is impaled on a spike. There is orcish lettering written on a dangling cloth.
0 0 0 0 0 -1 -1 0 0 0
If this stuff isn't easy to read, I can attach some source.
Does anyone have any clue as to why I'm having this wierd problem? I've tried to fix it but can't.
-edit-
I misquoted the exact messages printed by my debug code. I fixed that.