Reputation: 35
I am making a move function for a game and I get a expected expression error I can't figure out why, it seems legal what i did.
void Ant::move()
{
int dir=rand()%4;
if (dir==0)
{
if ((y>0) && (world->getAt(x,y-1)==NULL))
{
world->setAt(x,y-1,world->getAt(x,y));
world->setAt(x,y,NULL);
y++;
}
}
else
{
if ((x<WORLDSIZE-1) && (world->getAt(x+1,y)==NULL))
{
world->setAt(x-1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x--;
}
}
else
{
if ((x<WORLDSIZE-1) && (world-getAt(x+1,y)==NULL))
{
world->setAt(x+1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x++;
}
}
}
The problem is the second else call.
Upvotes: 0
Views: 1670
Reputation: 13967
There is an if
missing after the first else. You have now
if {
...
} else { // here you need an if - or revise the structure
} else {
}
For instance try ...
void Ant::move()
{
int dir=rand()%4;
if (dir==0)
{
if ((y>0) && (world->getAt(x,y-1)==NULL))
{
world->setAt(x,y-1,world->getAt(x,y));
world->setAt(x,y,NULL);
y++;
} else
if ((x<WORLDSIZE-1) && (world->getAt(x+1,y)==NULL))
{
world->setAt(x-1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x--;
} else
if ((x<WORLDSIZE-1) && (world-getAt(x+1,y)==NULL))
{
world->setAt(x+1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x++;
}
}
}
Upvotes: 0
Reputation: 375
I think the problem is:
world-getAt(x+1,y)==NULL
You forgot the >
world->getAt(x+1,y)==NULL
In the second if statement.
Upvotes: 1