• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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