[SOLVED] Issue with getting IDs of children using Parenting

J

JealousOfCrows

Guest
So in my last forum post I mentioned that I am basically making a list of objects that need to be deactivated rather than destroyed and then reactivated upon player death. The main purpose of this opposed to a room restart is to maintain certain surfaces in the room to show players where they have died etc...

So my problem here is that I tried doing this with a parent object that contains two objects as children. The code picks up the ids of one of the children, but not the other. It then throws this error.

In the step Event of the controller:

Code:
if (global.PlayerDeath == true)
{
    if ds_exists(List, ds_type_list)
    {
        var dsLength = ds_list_size(List);
        for (i = 0; i < dsLength; i++)
        {
            if (List[| i].Deactivated == true)
            {
                instance_activate_object(List[| i]);
                List[| i].Deactivated = false;
            }
        }
    }
}
############################################################################################
FATAL ERROR in
action number 2
of Step Event0
for object oController:

Unable to find any instance for object index '100052' name '<undefined>'
at gml_Object_oController_StepNormalEvent_2 (line 35) - if (List[| i].Deactivated == true)
############################################################################################

If I change the code in the controller object room start event from:
Code:
if !ds_exists(List, ds_type_list) List = ds_list_create();

////This will crash
if instance_exists(oParBreakable)
{
    with(oParBreakable)
    {
        ds_list_add(other.List, id);
    }
}
to activate the specific object directly, it works:
Code:
if instance_exists(oExplosiveBarrel)
{
    with(oExplosiveBarrel)
    {
        ds_list_add(other.List, id);
    }
}
Whats weird is in my testing I used a different object that was a child of the oParBreakable (oPoisonBarrel) to test and it worked fine. I have gone through and checked all the code and their is nothing different betweeen these two objects that would affect the id not getting picked up in the list. Obviously the fix is to just check each individual object quickly. But as I want this system to loop through all enemies in a room and save them to the list, this will quickly result in a ton of code and I would rather just do it for the master parent of all the enemies. Is this a bug? Have I done something wrong here? Please let me know if you think you know what may be the case!

Thanks for your time. Cheers.

EDIT: I removed the oPoisonBarrel from being a child to the oParBreakable object and it now works. However, when I add the oPoisonBarrel back into the child structure, the oPoisonBarrel no longer works....so it seems that its only getting the first child object. Anyone know why this is?

EDIT #2: Issue is SOLVED. Everything posted above actually works. After a bit of debugging it turns out my explosive barrel spawns an explosion object which actually destroys other breakable objects around it rather than deactivating them. This is why the error couldnt find an instance of the object! DERP. Thanks for helping guys! Really appreciate it!
 
Last edited by a moderator:

PNelly

Member
I'd recommend taking a crack at this with the debugger. You can examine what all instances are present, what their variable states are, the contents of data structures, and put breakpoints in your code to stop execution in precise places and examine what's going on.
 
P

ph101

Guest
I'm not seeing how or when you are deactivating instances? Or why you would add them to the list at the room start event ? Isn't the idea to make a list of deactivated objects?

Some thoughts:

-At a guess, perhaps you are adding objects to your list multiple times via performing list add code via a "with" on a parent and also latterly a child cell?
-is your list global? Do you ensure it is empty at the start of each room (if needed). (clear it)
-Some easy things to check would be the size of the list as you deactivate things via show_debug_message.
-Also - you shouldn't really need this deactivated variable if you maintain your list correctly (which you are going ot have to do) - you can just check if its in the list and therefore reactivatee (*assuming you add to list when you deactivate it...?)
-
 
J

JealousOfCrows

Guest
Sorry for the confusion.

On room start, I go through and grab all instances that I want in my list. These are instances that will be deactivated instead of destroyed and then reactivated upon player death. The instance themselves(or their parent) will turn on a variable "Deactivated", this will then trigger some code (similar to putting code in a destroy event) and then deactivate the instance. This happens in the specific object and I use this as a handle to check which instances have actually been deactivated in order to reactivate them as you can still access a deactivated instances data in this way (don't want to reactivate objects that arent activated, not sure what this will do but this prevents anything like that).

At the room end event I destroy the list, which will be recreated in the room start event with the new ids of the objects I need. So basically I just have a list of instance ids like enemies and platforms that can be destroyed (or in this case deactivated) and then when the player dies, i loop through them all, check if they are deactivated and then reactivate them.

The main problem here is that by using with(Parent) and then adding the ids, I am not getting all the ids of the all the children of that parent.
 
Top