I got the Robby the robot ai code and i'm trying to get it to scan for food, get health from it. The code i have works except after it picks up food it doesn't continue searching. Here's the code:
action robby_the_robot
{
creature = me;
creature.healthpoints = 100;
my.enable_entity = on;
my.enable_impact = on;
my.enable_block = on;
ent_create (healthbar_mdl, my.pos, display_health);
my.event = robby_event;
// my.ENABLE_SCAN = on;
//
// my.event = rotate_now;
ent_create(antenna_pcx, nullvector, check_front);
while(1)
{
standing_time = 3 + random(1); // stand for 3..10 seconds
while (standing_time > 0)
{
standing_time -= time / 16;
ent_cycle("stand", my.skill20); // play "stand" animation
my.skill20 += 2 * time;
my.skill20 %= 100; // loop
wait (1);
}
walking_time = 10 + random(10); // walk for 10..20 seconds
walk_speed.x = 3;
walk_speed.y = 0;
walk_speed.z = 0;
walk_speed *= time; // keep the same speed at different frame rates
wait (1);
while (walking_time > 0)
{
///////////////////////////////////////////
while (grub == null) //////<---------this code gets rid of empty pointer error, but freezes the AI after he picks up the food.
{wait (1);}
if (vec_dist (my.x, grub.pos) < 200) // the player approaches the food
{
// name_ent2();
vec_set(temp, grub.pos);
vec_sub(temp, my.pos);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac

walk_speed.x = 10 * time;
walk_speed.y = 0;
walk_speed.z = 0;
ent_move(creature_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed
// ent_playsound (my, walk_snd, 50);
wait (1);
}
/////////////////////////////////////////////
if (content(front_coords) == content_solid)
{
my.skill40 = my.pan;
my.skill41 = 30 + random(90);
while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees
{
my.pan += 3 * time;
wait (1);
}
}
else
{
walking_time -= time / 16;
ent_cycle("walk", my.skill20); // play "walk" animation
my.skill20 += 4 * time;
my.skill20 %= 100; // loop
move_mode = ignore_passable; // ignore passable entities
result = ent_move (walk_speed, nullvector);
if (result == 0) // got stuck!
{
walk_speed.x *= -1; // reversed movement
my.skill40 = my.pan;
my.skill41 = 30 + random(90);
while (my.pan < my.skill40 + my.skill41) // rotate 30..120 degrees
{
my.pan += 3 * time;
ent_cycle("walk", my.skill20); // play reversed "walk" animation
my.skill20 -= 4 * time;
my.skill20 %= 100; // loop
move_mode = ignore_passable; // ignore passable entities
ent_move (walk_speed, nullvector);
wait (1);
}
walk_speed.x *= -1; // restore walk_speed
}
}
wait (1);
}
wait (1);
}
}