Original Post
Here is my code:
if (player->GetXPos()+(AniOffsetX/2)+60 >= Grid[0].Pos.x && player->GetXPos()+(AniOffsetX/2) <= Grid[0].Pos.x+60 && player->GetYPos()+(AniOffsetY/2)-60 <= Grid[0].Pos.y && player->GetYPos()+(AniOffsetY/2) >= Grid[0].Pos.y-60)
{
CollisionSideCheck(0);
}
for (int i = 1; i < GridNum; i++)
{
else if (player->GetXPos()+(AniOffsetX/2)+60 >= Grid.Pos.x && player->GetXPos()+(AniOffsetX/2) <= Grid.Pos.x+60 && player->GetYPos()+(AniOffsetY/2)-60 <= Grid.Pos.y && player->GetYPos()+(AniOffsetY/2) >= Grid.Pos.y-60)
{
CollisionSideCheck(i);
}
}
else
{
player->SetCollision(None);
}
And it compiles this error twice:
error C2181: illegal else without matching if
What I have is an object which needs to check if it's colliding with an array of objects which needs to start with an if statement followed by else if statements. To avoid writing else if statements for every object in the array I thought I would put it in a loop but the compiler doesn't like the fact that the else if statement is in a loop. Anyone know a workaround? Thanks.
if (player->GetXPos()+(AniOffsetX/2)+60 >= Grid[0].Pos.x && player->GetXPos()+(AniOffsetX/2) <= Grid[0].Pos.x+60 && player->GetYPos()+(AniOffsetY/2)-60 <= Grid[0].Pos.y && player->GetYPos()+(AniOffsetY/2) >= Grid[0].Pos.y-60)
{
CollisionSideCheck(0);
}
for (int i = 1; i < GridNum; i++)
{
else if (player->GetXPos()+(AniOffsetX/2)+60 >= Grid.Pos.x && player->GetXPos()+(AniOffsetX/2) <= Grid.Pos.x+60 && player->GetYPos()+(AniOffsetY/2)-60 <= Grid.Pos.y && player->GetYPos()+(AniOffsetY/2) >= Grid.Pos.y-60)
{
CollisionSideCheck(i);
}
}
else
{
player->SetCollision(None);
}
And it compiles this error twice:
error C2181: illegal else without matching if
What I have is an object which needs to check if it's colliding with an array of objects which needs to start with an if statement followed by else if statements. To avoid writing else if statements for every object in the array I thought I would put it in a loop but the compiler doesn't like the fact that the else if statement is in a loop. Anyone know a workaround? Thanks.