# Thread: Unlucky 13

1. ## Unlucky 13

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.

2. Don't know what xx and yy are, exactly, but: you can only get to location 13 if xx is between 21 and 56 and if yy is between 21 and 57. You then immediately leave location 13 if xx is between 22 and 57 and yy is between 22 and 58. So yes, you are going to immediately leave unless xx is exactly 21 and yy is exactly 21.

3. x and y are globals and xx and yy are variables within the function, but since 13 follows 8 I need to change all the locations to else ifs I am guessing.... duh.. I thought chaging x and y before hitting the location would keep me from transporting back, but I forget my checks were using local variables and not the globals as reference...... *hits himself in the head* duh.
Thank you

4. Mayb its wat they were coding while having The Last Supper.....13..

Popular pages Recent additions