Delete Specific Objects

C

Chris White

Guest
i want to be able to place an object down with LMB then remove that specific object with RMB, this works great but when i right click on the object it removes all of them in the room. How would i delete only the one i click on?

Thanks
-Chris
 
N

NPT

Guest
You need to show your code.

It sounds like you are incorrectly prefixing an object name, or confusing instances with objects. But without seeing your code we can only guess.
 
C

Chris White

Guest
You need to show your code.

It sounds like you are incorrectly prefixing an object name, or confusing instances with objects. But without seeing your code we can only guess.

Code:
if mouse_check_button_released(mb_left)
{
    instance_create(mouse_x,mouse_y, objchange)
}
if mouse_check_button_released(mb_right) and position_meeting(mouse_x,mouse_y, objchange)
{
    with objchange instance_destroy() //Wasn't sure how to delete another object, but this worked fine.
    instance_create(0,0,mouseplace)
}
This was just a quick room persistence test for a game im making so excuse the poor naming conventions.
 
Last edited by a moderator:
N

NPT

Guest
Your problem is with:
with objchange instance_destroy()

That line iterates through all instances on objchange and then deletes each one.
 
C

Chris White

Guest
Your problem is with:
with objchange instance_destroy()

That line iterates through all instances on objchange and then deletes each one.
I got it working to the point where when i right click on the object it only deletes that one, but then if i place multiple and delete the last one i placed it deletes all previous ones before it.
 
N

NPT

Guest
The code as you presented will ALWAYS delete all instances of objchange.

You need to isolate just the single instance under the cursor, you can do that with instance_position().
Code:
if mouse_check_button_released(mb_left)
{
    instance_create(mouse_x,mouse_y, objchange)
}
if mouse_check_button_released(mb_right) and position_meeting(mouse_x,mouse_y, objchange)
{

    with instance_position(mouse_x, mouse_y, objchange) instance_destroy();  
     
    instance_create(0,0,mouseplace)
}
 
C

Chris White

Guest
The code as you presented will ALWAYS delete all instances of objchange.

You need to isolate just the single instance under the cursor, you can do that with instance_position().
Code:
if mouse_check_button_released(mb_left)
{
    instance_create(mouse_x,mouse_y, objchange)
}
if mouse_check_button_released(mb_right) and position_meeting(mouse_x,mouse_y, objchange)
{

    with instance_position(mouse_x, mouse_y, objchange) instance_destroy(); 
    
    instance_create(0,0,mouseplace)
}
Awesome, that works perfectly! Thanks
 
Top