• 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!

GameMaker Function destroying wrong object

I am using the collision_line_list function to detect all objects of a type.

In this case, the object is obj_CapMan.

Code:
collision_line_list(obj_HatMan.x,obj_HatMan.y,mouse_x,mouse_y,obj_CapMan,false,true,listaCap,false);

This code is in an object that would be equivalent to the game administrator. What should not influence anything, but in any case, is the information.

Full Code:

listaCap=ds_list_create();
listaNum=collision_line_list(obj_HatMan.x,obj_HatMan.y,mouse_x,mouse_y,obj_CapMan,false,true,listaCap,false);

if(listaNum>0){
instance_destroy(listaCap);
ds_list_destroy(listaCap);
}


As a result, none of the objects on the list are being destroyed, but another one that is neither the manager nor the obj_CapMan, is being destroyed.

Documentation Link:

https://manual-en.yoyogames.com/#t=...e&rhhlterm=collision_line_list collision_line

-----

1620514001910.png


This red square is an object to detect a headshot.


That same object that is being destroyed, even though it is not mentioned in that part of the code at any time:

1620514020713.png
 

chamaeleon

Member
instance_destroy() does not take a ds_list as argument, so why are you passing it instead of an instance id? Passing something of incorrect type to a function will most assuredly result in unexpected and/or invalid behavior. Iterate over the content in listaCap and do whatever you need to with each stored instance, including destroying such an instance.
 
instance_destroy() does not take a ds_list as argument, so why are you passing it instead of an instance id? Passing something of incorrect type to a function will most assuredly result in unexpected and/or invalid behavior. Iterate over the content in listaCap and do whatever you need to with each stored instance, including destroying such an instance.
I managed to solve the problem. I did exactly what was indicated in the documentation and got the expected result. All of this happened, because before, I used to repeat instead of for. As a result, an error was occurring when indicating the index of the "vector" of the list.
 
Top