suppose that a is not equal any one of those!! so it shouldnt try to do any action!
but what happens that if they are all false it ignore the last "if" condition and do action 3
i only solve it by doing something like this:
Or maybe to help clean up the jumble of ifs, ands, or buts you could try doing something like the code below. As you can see it's much cleaner and may help you out with forgetting a else or a bracket somewhere, and depending on what compiler your using and how you have it set to optimize, it may also be faster then an if/else nest But that's a whole different discussion that we don't need to get in to.
int a = 1;
switch(a)
{
case 1:
action1();
break;
case 2:
action2();
break;
case 3:
action3();
break;
default:
printf("Something went wrong, 'a is defined as %d",a);
a = 0;
break;
}
if(posx>posx2+1||posy<posx2-1)
{
if((mymap[posy2][posx2-rx])==1)
{
a.destx=posx2-rx;
a.desty=posy2;
}
else
if((mymap[posy2][posx2+rx])==1)
{
a.destx=posx2+rx;
a.desty=posy2;
}
else
if((mymap[posy2-rx][posx2])==1)
{
a.desty=posy2-rx;
a.destx=posx2;
// mymap[posy2-rx][posx2]==4;
}
else
if((mymap[posy2+rx][posx2])==1)
{
a.desty=posy2+rx;
a.destx=posx2;
//mymap[posy2+rx][posx2]==4;
}
else
{
[b]if i put these 2 codes it works but if i deleted them it goes wrong![/b]
//a.desty=a.chary;
//a.destx=a.charx;
}
if(posx>posx2+1||posy<posx2-1)
{
if((mymap[posy2][posx2-rx])==1)
{
a.destx=posx2-rx;
a.desty=posy2;
}
else if((mymap[posy2][posx2+rx])==1)
{
a.destx=posx2+rx;
a.desty=posy2;
}
else if((mymap[posy2-rx][posx2])==1)
{
a.desty=posy2-rx;
a.destx=posx2;
// mymap[posy2-rx][posx2]==4;
}
else if((mymap[posy2+rx][posx2])==1)
{
a.desty=posy2+rx;
a.destx=posx2;
//mymap[posy2+rx][posx2]==4;
}
else
{
[b]if i put these 2 codes it works but if i deleted them it goes wrong![/b]
//a.desty=a.chary;
//a.destx=a.charx;
}