I thought that was what the 'switch (my.state)' bit was for. When the enemy is created I give it the function state_wait. When the if condition of that function is fulfilled, surely it would change to case 2 - function state_attack?