I'm having some troubles with a function I've written. Basically it turns an object into a chicken that randomly around walks and pecks at the ground.
The function is called in a room's repeatedly_execute. It works just how I want it to, apart from one small problem. When the chicken stops walking, I need the walking animation to stop.
The AGS scripting language is new to me and I can't for the life of me figure out how I might go about this. If I could somehow store the destination coordinates for each object I could compare the current coordinates and call object[num].StopAnimating(); when they match.
There's probably a much easier way of doing this, but here's the function:
Code: ags
The function is called in a room's repeatedly_execute. It works just how I want it to, apart from one small problem. When the chicken stops walking, I need the walking animation to stop.
The AGS scripting language is new to me and I can't for the life of me figure out how I might go about this. If I could somehow store the destination coordinates for each object I could compare the current coordinates and call object[num].StopAnimating(); when they match.
There's probably a much easier way of doing this, but here's the function:

function Pecker(int num) {
// If chicken is not moving
if (object[num].Moving == false) {
int rnd = Random(100);
// Move
if (rnd == 1) {
// Get new coordinates
int new_x = object[num].X + PosNegInt(Random(20));
int new_y = object[num].Y + PosNegInt(Random(10));
// Get direction object is facing, start animating
if (new_x > object[num].X) {
object[num].SetView(5, 0);
object[num].Animate(0, 4, eRepeat, eNoBlock);
}
else {
object[num].SetView(5, 1);
object[num].Animate(1, 4, eRepeat, eNoBlock);
}
// Move to new coordinates
object[num].Move(new_x, new_y, 1, eNoBlock, eWalkableAreas);
}
// Peck ground
else if (rnd > 98) {
if (FacingLeft(object[num].Loop)) {
object[num].SetView(5, 8);
object[num].Animate(8, 4, eOnce, eNoBlock);
}
else {
object[num].SetView(5, 9);
object[num].Animate(9, 4, eOnce, eNoBlock);
}
}
}
}