It's a text adventure program, and this only pops up during the battle sequence, and even then, on rare occasions. Line 1891 is int main() so I have no idea what the problem could be.
I have. And I'm not sure how to, I click retry, and it takes me to a file called stdthrow.cpp, I've since edited the code, and now nothing is on line 1891, but when I run the program, sometimes I get that same error, telling me there's an error on line 1891.
It is as the error message said:
You are doing something with a std::string and you are passing a bad (NULL) pointer
to a string member function.
I looked at xstring and on my system - and all the functions around line 1891 area are the find_*** functions - for example find_first_of , find_last_of.
int Attack(int a){
if(currentPlayer == HUMAN_PLAYER){
do{
if(Cstats.currentweapon == Table[x].Name){
Dmgvalue = Table[x].Damage;
yes = false;
}else
{
x++;
yes = true;
}
}while(yes != false);
AttackRoll = (1 + rand() % (20)) + Cstats.BaseAttk;
if(AttackRoll >= Mob[m].ArmorClass){
Mob[m].Health -= Dmgvalue;
cout << "---------------------------------------------------------------" << endl;
cout << "YOU USE YOUR " << Cstats.currentweapon << " TO CHOP THAT "<< Mob[m].Name << "'s ARM OFF!!!!" <<endl;
}else{
cout << "---------------------------------------------------------------" << endl;
cout << "YOU MISS!!!" <<endl;
}
}
else
{
cout << "The " << Mob[m].Name << " is making an attack!" << endl;
Sleep(3000);
do{
if(Mob[m].Weapon == Table[y].Name){
MobDmg = Table[y].Damage;
yes = false;
}else
{
y++;
yes = true;
}
}while(yes != false);
AttackRoll = 1 + rand() % (20);
if(AttackRoll >= inventory[0].ArmorClass){
Cstats.Health -= MobDmg;
cout << "THE " << Mob[m].Name << " CUT YOUR BLOODY HAND OFF" <<endl;
}else{
cout << "He missed!" << endl;
}
}
//do we have a winner?
if(Cstats.Health <1 || Mob[m].Health < 1)
{
if(currentPlayer == HUMAN_PLAYER)
{
cout<< "You WIN! Congratz!" << endl <<endl;
if(a==0)
{
Cstats.Exp += Mob[m].Exp;
save();
cout << "You now have " << Cstats.Exp << " experience points. You have " << reqxp-Cstats.Exp << " experience points left until you level up." << endl;
if(Cstats.Exp>=reqxp)
{
Level();
}
}
elseif(a==1)
{
cout << "Moving on to next battle." << endl;
return 1;
}
elseif(a==2)
{
cout << "You've beaten The Arena! Congratulations!" << endl;
return 2;
}
}
else
{
cout<< "You DIE!" <<endl << endl;
}
}else{
currentPlayer = !currentPlayer;
}
return 0;
}
It's only appearing when the Mob is attacking, the main else in this code. I've never experienced it in the part where the player attacks, or it displays a victory message, or a defeat message.
Also, I'm getting the error in another part of my code now too, along with this part still. I'm not sure why I'm getting it in this part now either. It's in a part of the code where the user can use an item like a potion to heal. The user can access the item use screen from two areas, when their viewing their inventory, and when the battle sequence is active. I have never experienced the error when accessing the use items function from the battle sequence, yet whenever I access it from the inventory, I always get the error. I have no idea why, both the inventory and battle sequence call the function the same way, and it doesn't take in a variable, so it's not like it's using something it shouldn't be.
struct Monster{
int Health;
string Name;
string Armor;
int ArmorClass;
string Weapon;
int Exp;
}Mob[100];
Also, I just figured out that the problem IS in the loop. I just had the program output messages before, during and after the loop. Whenever the program breaks with that error, only the messages before and during appear. It seems like my variable "y" is incrementing too much. However, setting it equal to zero before it enters the loop does not solve the error.
Well...I might feel like an idiot after asking this. Especially if this was what was causing the error. But! How possible is it that in the Table[y] array, if I had a certain array spot filled, and then filled it again with new data right after, be the cause of it?
Because, I'm not sure how I missed it, or how I even did it, but I had written this in my code. I've been testing my program since I changed it, and have yet to experience the error, but, like I said earlier, it only appears on rare occasions.
But could this have been what was causing the error?