Cannot delete from ds_list.

When an enemy approaches a player, I add him to the list of attacking enemies.

GML:
if instance_exists(obj_Par_Player)
nearest_character_ = instance_nearest(x, y + z, obj_Par_Player);
if(point_distance(x, y, nearest_character_.x, nearest_character_.y) < 40
&& ds_list_size (obj_Par_Player.enemy_ds_list_) < 2
&& ds_list_find_index(obj_Par_Player.enemy_ds_list_, id) == -1)
{
    ds_list_add(obj_Par_Player.enemy_ds_list_, id);
}
How can I remove an enemy from the list if the character escapes from him? It does not work for me.

GML:
if(point_distance(x, y, nearest_character_.x, nearest_character_.y) > 40
&& ds_list_find_index(obj_Par_Player.enemy_ds_list_, id) == id)
{
     ds_list_delete(obj_Par_Player.enemy_ds_list_, id);
}
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
ds_list_find_index returns the position of an element in a list. You are comparing this to id, which is decidedly not a list position. Did you mean to check if the list position is greater than -1, as in, existent?
 
Top