I have been trying to figure this out for two hours. I have a game that changes your "background" based on a value saved in int location. Once I got to programming location 13 things started to fall apart. I have a move function that checks for a barrier before applying the move. The barrier bool function is quite lengthy and checks x and y values based on the value of location. If you meet certain requirements its a wall, stairs, bossfight, zone to next map, ect. The system has worked easily thus far. Before I made the barrier requirements for location 13 I was able to walk freely in that area to check if the new monster fights worked, and they did. I then added this
Code:
if(location == 13)
{
if(xx >= 22 && xx <= 57 && yy >= 22 && yy <= 58)
{
location = 8;
x = 60;
y = 30;
displayarea();
}
else if(xx >= 0 && xx <= 20 && yy >= 0 && yy <= 95)
{
return true;
}
.......
......
else
return false;
}
as soon as I pass to location 13 it immediately sends me back to location 8 without even displaying location 13. If I comment out the contents of the first if statement I can walk through the map fine all my walls work and you can't walk through them. You can even get in random battles. This is not what I expected. I thought if the first if always evaluated as true which it seems to do when its contents are not commented, then all the other else if statements would not be tested and I would not be able to move at all since the bool never evaluated as true or false. I cannot figure out whats happening here. Also the only code in the game that makes location = 13 is as follows
Code:
if(location == 8)
{
if(xx >= 49 && xx <= 112 && yy >= 28 && yy <= 112)
{
if(bossesfought[0] != 1)
{
bossfight = true;
oldlocation = location;
location = 0;
}
}
if(x >= 640)
{
location = 9;
x = 0;
displayarea();
}
else if(y >= 480)
{
location = 11;
y = 0;
displayarea();
}
.....
.....
.....
else if(xx >= 263 && xx <= 317 && yy >= 110 && yy <= 158)
{
savegame();
}
else if(xx >= 21 && xx <= 56 && yy >= 21 && yy <= 57)
{
if(bossesfought[0] == 1)
{
x = 90;
y = 30;
location = 13;
displayarea();
}
}
else
return false;
}
I am supremely confused because I can't find a logical explanation for the glitch. Any insight would be helpful. Thanks in advance for your time.