Legacy GM [SOLVED] Delete objects in region

TheRBZ

Member
I have a script to automatically generate a 'forest' out of tree objects but I want to have a bare patch in the middle. I wanted to accomplish this tree-less patch in the middle by deleting the tree objects within a radius with collision_circle but my code seems to do nothing.
Mainly I'm looking to use 'with' and call to all the objects in the collision rather than one.
Code:
///scr_generate_trees()
var xx;
var yy;

for (yy = 0; yy <= room_height; yy += 32;){ //do a vertical row
    for (xx = 0; xx <= room_width; xx += 32 * (choose(1,2)); ){ //do a horizontal row
        instance_create(xx,yy,obj_tree);
    }
}

if collision_circle(room_width/2,room_height/2,32*4,obj_tree,false,true){
    with(other){
        instance_destroy();
    }
}

/* ==================================================
   This generates trees one horizontal line at a time
   ================================================== */
Any help? Thanks
 

TheRBZ

Member
Code:
with(collision_circle(room_width/2,room_height/2,32*4,obj_tree,false,true)){
    instance_destroy();
}
Doesn't work either

Code:
with(collision_circle(room_width/2,room_height/2,32*4,obj_tree,false,true)){
    show_message("worked");
}
Then tried this but only got one "worked"
 

FrostyCat

Member
Where does this misguided "collision functions change the value of other" myth come from?

Stop using other in use cases that won't support it, and do it right. One solution is to keep checking the region until it no longer hits anything:
Code:
var ci;
do {
  ci = collision_circle(room_width/2, room_height/2, 32*4, obj_tree, false, true);
  if (ci != noone) {
    with (ci) instance_destroy();
  }
} until (ci == noone)
Alternatively, change perspective into the instances and have them check the collision against themselves:
Code:
with (obj_tree) {
  if (collision_circle(room_width/2, room_height/2, 32*4, id, false, false) != noone) {
    instance_destroy();
  }
}
Repeat after me:
  • I will only use other to refer to colliding instances in a REAL collision event.
  • collision_*(), place_meeting(), instance_place(), position_meeting() and instance_position() are NOT real collision events. I will stop treating them like one.
  • collision_*(), instance_place() and instance_position() return an instance ID for me to use when there is a collision. I will stop pretending that they return Booleans.
 

MirthCastle

Member
You could also just make an invisible object the size of the Collision Circle, and in it's Collision event with object tree. Destroy the tree. When there are no trees colliding, destroy itself.

That way you are not scanning every tree in existence like you would be in the With function.

You could also build upon that, and use x_scale and y_scale to change the size and shape of the destroyer object. Furthermore, you could change the object the destroyer object looks to collide with in its create event and you will have a multiuse tool.

:)
 
Top