Assuming the code you posted is working right now (except for nearest part),

what you should do is simple.
set my.enemy to null at the start of the function.

then before the my.enemy = you like check 2 things.

1- if my.enemy is already null set my.enemy to you.
2- if my.enemy is not null, you are going to check if current my.enemey is farther away from new "you". you can use if(vec_dist(me.x,my.enemy.x)>vec_dist(me.x,you.x)) .
if that is true then entity stored in my.enemy is not closer, the one in you is closer so you set my.enemy = you.


3333333333