(SOLVED) How to access the name of a structure child created during runtime

Greetings,

I’m once again taking a stab at source dependent immunity frames, I won’t rest until I finally make it work!!

THIS TIME, I think I’m finally close to cracking it, but I’ve hit a roadblock. I’ve commented everything in the screenshots, but allow me to give the basics of how I want this to work:

When an enemy is hit by an attack that can pierce, it’s UID is added to a structure variable as a child, with it’s value set to the attack’s immunityTime variable (For immunity frames). Each child variable’s value decreases by 1 per frame, and once it hits 0, delete it from the structure

This way, if an enemy is hit by an attack, but you want the enemy to be hit by that particular instance of the attack again (Without interfering with other attacks or becoming immune to everything), then this allows such a thing to happen

This is useful for attacks that linger, lasers, big projectiles, etc

So far, I’ve gotten the piercing system set up and good to go, but I have an issue with the structure child code

When I check the debugger, this is what’s happening…

  1. The child’s value does not decrease until the next bullet is fired
  2. The child’s value stops decreasing once the bullet that hit it no longer exists (Destroyed offscreen)
  3. The child’s value is decreasing much slower than expected for some reason

What I WANT to have happen is…

  1. For each child, the moment they exist, decrease their value by 1 per frame
  2. Once that value is empty, the child deletes itself

The culprit is that the child is still keeping track of the bullet that hit it, but I don’t know how to access the child’s name in the condition when the name is the UID created during runtime, and for some reason “For each child” doesn’t exist for object structures…

So… is there a way I can access the name for each individual child structure when they’re created during runtime? I feel like I’m sooo close to the answer, but I can’t quite figure it out

If it was an array, you could use a repeat event with a variable counter but for a structure object variable the only thing I can think of is to copy the object variable to a scene variable and use for each child on it. Or maybe use a scene variables that is reference by the enemy and/or projectile ID.

Something like this. I used the drag behavior to test the collisions and a DeleteZone object to delete the enemy which might correspond to your projectiles.

Scene variables

I don’t think I did it right

As much as I’d like to use an array, unfortunately, I need the UID stored as extra information so that the game can track each individual instance of projectile, as well as the value that decreases over time, which is why I use a structure

Unless it’s possible to use an array to store both the UID and the immuneTime…?

I’ll look at your events later. But you can have an array of structures.

I’m not 100% clear on your method but I think the object in the NOT should be your hurtfulThings object if that’s the 1 with an ID or UID.

I’m not use if the 2 conditions is needed or maybe it and the NOT need to be in an OR. The NOT condition is to check if the object was deleted. (the hurtfulThing)

Hmmm, considering “For each child” exists for scene and global variables, I considered maybe reworking the code to have the source dependent immunity frames take place in a scene variable instead?

Here’s the plan I have laid out:

I tried to accomplish this, but got stuck here:

I didn’t get to the “For each child” part yet because I’m still struggling to get the scene variables to work properly. When a bullet hits, it just adds new scene variable children instead of updating the existing ones

This did catch my attention though. This implies that I can just accomplish my code like how I was doing it before, but just with an array of structures instead of a structure with structures. I’m assuming I might need the ArrayTools extension to make this work

Which one would you recommend? The scene variable method, or the array of structures method?

If you used an array of structures with an object then you still couldn’t use for each child but you could use a repeat number of children times with a variable that you increase.

Index=0
Repeat number of children times
… Object.VariableName[index].UID
… Index + 1

Another issue is that you couldn’t check if an ID exists with a simple condition. You would need to search the array for the child. You could simplify that by making your own condition in a function.

Index=0
Repeat number of children times
… Object.VariableName[index].UID = testID
… … Return true
… Index + 1

I this case a While event might be slightly quicker because you could leave the while event when the ID was found. The difference would be negligible if the array was small.

Using a scene variable would allow you to use for each child and the child exists condition. You could use the UID as a child.

I haven’t had the time to really study your events. Object linking might also help. You could link objects and use a for each child with linked objects. Again, IDK if that’s applicable without truly looking at your events and your intentions. You could do things like remove the UID from linked objects when the object was deleted.

1 Like

Hmmm, considering the limitations of what I was originally doing, it seems like the only option I have is to use a scene variable to handle source dependent immunity frames, considering “For each child” seems to be the most straightforward and optimal

I just gotta figure out how to add the information AS children TO the existing children. I’ll try experimenting more and get back to you if anything changes

I finally had some time to play. IMO it would be easier to give your character temporary invulnerability to everything for a few seconds instead of tracking the IDs using the health cool down.

Anyways, here’s my test project. I decided to put the ID structure on the hurtfulThing object. I felt that way if the hurtful object was deleted the structure would also be deleted.

I decided to use the Time from Start value to track the damage cool down.

I added text objects to track things like the time, health and IDs.

My scene

My objects.

The hurtfulThing objects have the IDs structure and the the drag behavior for testing. The enemy object has the health behavior and an ID variable. The time text object was added to the scene with the designer while the other text objects are added and stuck to the relative objects with events using the sticker behavior on the text objects.

I only used a few scene variables.

These are my events.

It doesn’t have any form of ID cleanup. I added the structure to the hurtfulThing objects so if they were deleted then the structure would. I guess if you linked the objects then if the enemy was deleted then the ID could be removed from the structure. If the Enemy is the player than it doesn’t matter. You could also purge the array after so long without a collision using an object timer which would also be deleted or maybe when the hurtfulThing was way off screen.

I though of using object timers with the name of the ID but you would need to go through the list of IDs. Too bad you couldn’t have a generic timer that could have multiple set times and then you could get the timer name when the timer went off or maybe a way to get the active timer names. IDK. I’m just thinking out loud.

1 Like

Thank youuuu, it appears that the answer was TimeFromStart(). Tbh, I’m still confused on how TimeFromStart() exactly works since documentation for it is kind of vague, but it really does work wonders for this use case!

Anyways, the new code is much cleaner, and I think more optimal. Having the structure on the attack instead of the enemy is a much cleaner solution, and I don’t even need to use the scene variables anymore!

Here’s my new code:

Here’s the result:
issue
(Note: Bullets have a limited amount of pierces and a lifespan set)

Thanks for your assistance, it works great!

2 Likes