Legacy GM RESOLVED instance not destroying

V

VansiusProductions

Guest
Hi guys,
This is my script and code for destroying specific instances using instance_place but it's not working, the instances are still there.
The code that is calling the script
Code:
if (x >= 352 && y = 62 && global.groupDeselect = 1) {
instance_destroy()
with (obj_element) {scr_hideElements()}
global.groupSelectedA = 0
global.groupIsDeselect = 1
}
if (x >= 352 && y = 222 && global.groupDeselect = 1) {
instance_destroy()
with (obj_element) {scr_hideElements()}
global.groupSelectedB = 0
global.groupIsDeselect = 2
}
The first instance_destroy() is for the calling object, the object that is not working is the one right below: obj_element where i call the script:
Code:
//obj_group_air
if (global.groupIsDeselect = 1 && global.groupSelectedA = 1) {
destroy = instance_place(512,62,obj_air)
with (destroy) instance_destroy()
}
if (global.groupIsDeselect = 2 && global.groupSelectedB = 1) {
destroy = instance_place(512,222,obj_air)
with (destroy) instance_destroy()
}
//obj_group_earth
if (global.groupIsDeselect = 1 && global.groupSelectedA = 2) {
destroy = instance_place(512,62,obj_earth)
with (destroy) instance_destroy()
}
if (global.groupIsDeselect = 2 && global.groupSelectedB = 2) {
destroy = instance_place(512,222,obj_earth)
with (destroy) instance_destroy()
}
Is there anything I'm doing wrong? Any help is appreciated
 

TheouAegis

Member
Are you destroying the calling instance before you destroy the instances found in destroy? If the calling instance is destroyed, it can't be "placed" anywhere.

Put before each of those with() calls:

show_message(destroy)

Make sure the message shows a number larger 100000.
 
T

Tyrell D. Barnes

Guest
Good day, VansiusProductions.

I'll give it to you straight: functions such as instance_place and collision_line, to name a couple, only return the ID of one instance within a group, which can be any one of the instances involved in said collisions. Theoretically, it is better to call the collision checks with the objects themselves, as they are better able to handle their own *demises*, if you catch my drift. I presume this is your situation.

As I stated before, a better way to put it is by having the objects themselves (air and earth) check for collisions with the object colliding with them, and have them handle the checks from there. This will involve copying code, so I would suggest putting them under a Parent object, for instance, or call it from a script you only need to write once, for efficiency purposes.

If this is not the issue you're having, then I apologize in advance. If you could, the best way is to post a link to your file for us to review and clearly debug the situation. Otherwise, this is the best bet by far.

All regards,
Tyrell D. Barnes
 
V

VansiusProductions

Guest
Are you destroying the calling instance before you destroy the instances found in destroy? If the calling instance is destroyed, it can't be "placed" anywhere.

Put before each of those with() calls:

show_message(destroy)

Make sure the message shows a number larger 100000.
Oh yeah i shouldn't have put instance_destroy before everything thanks!
 
Top