This is my entire code for birdrightobj step event:
if( myhealth<=0)
dead = true
if ( collision_point(x,y,starfishobj,true,true) )
{
starfishcollide=true
myhealth=myhealth-30
with(starfishobj)
{
instance_destroy()
}
}
// check for proximity
if( distance_to_object(crabobj) < closetrigger)
nexttome=true
// check for start/end of path
if( NPCState=="patrol" && path_index!= -1 )
{
if( path_position<=.01 && image_xscale==-1)
{
image_xscale=1
// GML 2.0 code
path_end()
path_start(birdpath,4,3,0)
////////////////
}
if( path_position >= .99 && image_xscale==1)
{
image_xscale=-1
}
}
// check for low health and set flag
if( myhealth <= 20)
lowhealth=true
// Part B //////////////////////////////////////////////////////////
// Update NPCState
////////////////////////////////////////////////////////////////////
if((starfishcollide || nexttome)&&NPCState=="patrol")
NPCState="attack"
if( NPCState=="attack" && lowhealth)
NPCState="retreat"
if( NPCState=="attack" || NPCState=="retreat" )
if( dead==true)
{
NPCState="dead"
sprite_index=deadbirdsp
speed=0
}
// Part C ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// Run State based on value of NPCState variable
// dead? then don't do anything
if(NPCState=="dead")
{
exit;
}
if(NPCState == "attack")
{
path_end()
direction = point_direction(x,y,crabobj.x,crabobj.y)
speed=3
if( distance_to_object(crabobj) < .01)
speed=0
//b = instance_create_layer(x,y,”instances”,objbullet) // gamemaker studio 2.0
if(!instance_exists(eggobj))
{
// b = instance_create(x,y,eggobj)
b = instance_create_layer(x,y,"instances",eggobj)
ammo=ammo-1
with(b)
{
direction = point_direction(x,y,crabobj.x,crabobj.y)
speed = 5
}
}
}
if(NPCState == "retreat")
{
path_end()
nearnest = instance_nearest(x,y,nestobj)
if( x==nearnest.x && y==nearnest.y)
{
speed=0
myhealth=100
NPCState="attack"
}
else
{
direction = point_direction(x,y,nearnest.x, nearnest.y)
speed=5
}
}