0
\$\begingroup\$

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=GameMaker_Language%2FGML_Reference%2FMovement_And_Collisions%2FCollisions%2Fcollision_line_list.htm&rhsearch=collision_line&rhhlterm=collision_line_list%20collision_line


enter image description here

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:

enter image description here

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

There's an error in your code:

instance_destroy(listaCap);

You are destroying the instance referenced by listaCap, which is a data structure instead. GameMaker Studio doesn't have strong language types, and treats listaCap like a regular resource id; since you used it in the instance_destroy() function, GMS pretends it is an instance id and does its job. The result is, a random object is being destroyed.

You can fix your code by accessing the content of your ds_list and destroying the referenced instance:

if (listaNum > 0) {
    for (var i = 0; i < listaNum; ++i) {
        instance_destroy(listaCap[| i]);
    }
    ds_list_destroy(listaCap);
}

Additionally, you may want to check if there's one instance only in your ds_list before destroying it, just to make sure no more issues arise.

\$\endgroup\$
4
  • \$\begingroup\$ At first I tried to do something like that. I put it inside a repeater and tried to destroy it using [| i]. But the program was not recognizing the list as a vector. \$\endgroup\$ Commented May 8, 2021 at 22:51
  • \$\begingroup\$ I will make the changes you indicated and I will return with the result. \$\endgroup\$ Commented May 8, 2021 at 22:51
  • 1
    \$\begingroup\$ You can also use ds_list_find_value() to read values alongside accessors. \$\endgroup\$ Commented May 8, 2021 at 22:57
  • \$\begingroup\$ What would the line look like: instance_destroy(ListCap[| i]); . If the list were a vector? listaCap[i] \$\endgroup\$ Commented Jun 17, 2021 at 22:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.