How do I break the chain?

Not favoritedFavorited Favorited 0 favourites
From the Asset Store
A heart-pounding album featuring 8 electrifying tracks designed to fuel epic battles and high-stakes confrontations.
  • I have a unique problem in my hands.

    So I have a system that attaches sprites in a chain. When that chain breaks, I hope that the sprites detach accordingly. Unfortunately the below circled sprites act as if still attached!

    I've already figured out how I'd want the sprites to act. The question is this: what do I put in the conditions tab to make it so the system checks for a break in the chain?

  • How do you make the chain? With hierarchy, physics, pin, or something else?

    Which sprite is attached to which sprite? Molec to Chemic?

  • The chain is made with events.

    So the initial part of the chain is the Chemic itself, then another Molek or set of moleks that will then be destroyed upon touching alpharay. (Or betaray, which I don't have in the example but I do have in the rest of the project.)

    Thing is, I tried the condition of overlapping Chemic or Molek but neither worked.

    I think the solution might have something to do with the markers themselves. Maybe if I can have the system check if 4 markers can be looped around a molek, for it to then detach.

    How would I go about making that a condition, however?

  • I don't understand what you're calling a chain then. I don't see any physical connection between objects in your screenshots — so what exactly is the chain, and what do you need to do to break it? What are the markers used for?

    The very first event in your screenshot probably creates hundreds of markers every second, because it runs on every tick. So that’s definitely wrong — unless the third event immediately destroys them? Have you tried running the game in Debug Mode? Run the debugger, create a chain, hit pause, and check all objects, their instance variables, the dictionary content, and so on.

    Your code is confusing, and I’m afraid you might be the only person who fully understands it...

  • There's more to the code than I can successfully screenshot, I'll be able to show you via the project file itself:

    drive.google.com/file/d/1x-GN_g_PbKfzClApM8vNFcr6RX3ITA5r/view

    Bear with me, the link should work, but I'm not entirely sure how to do it with Dropbox, so I did it through Google Drive instead.

  • I sort of get your idea, but I think it's overly complicated and hard to troubleshoot. You're destroying and recreating all markers and repopulating the dictionary on every tick, which makes it even more confusing.

    I’d strongly suggest using the hierarchy feature instead, it will be A LOT easier. Attach Moleks to Chemic as children - this way, they’ll automatically move together and stay logically connected. You won’t need dictionaries or extra variables at all. You can find parent or child object at any time with "Pick parent/child" condition.

    There are two ways to build the hierarchy: either attach all Moleks directly to the parent Chemic, or create a chain. I’m guessing the chain would be more suitable in your game. If a middle (blue) Molek in the chain is removed, it will automatically break into two smaller chains. Or you can detach pink molek from yellow as well.

  • There are two ways to build the hierarchy: either attach all Moleks directly to the parent Chemic, or create a chain. I’m guessing the chain would be more suitable in your game. If a middle (blue) Molek in the chain is removed, it will automatically break into two smaller chains. Or you can detach pink molek from yellow as well.

    I'll try for the latter case in this instance. Basically anything breaking off from the chain will act as they would if Z were pressed, and (in this example) pink and yellow would bullet out of there separately from each other.

    I’d strongly suggest using the hierarchy feature instead, it will be A LOT easier. Attach Moleks to Chemic as children - this way, they’ll automatically move together and stay logically connected. You won’t need dictionaries or extra variables at all. You can find parent or child object at any time with "Pick parent/child" condition.

    The dictionary will be necessary for another aspect of the overall project that this stems from, where I'll need to call on it for an overall shape to be built, checking if numbers match the shape intended.

    construct.net/en/forum/construct-3/how-do-i-8/check-shape-built-185425

    It seems to be the only thing that works so far, and to remove the dictionary entirely would mean to overhaul this system that's worked for me.

    With all this in mind, where would you suggest the overhaul begin?

  • With all this in mind, where would you suggest the overhaul begin?

    I don't know.. Perhaps you could build the dictionary when needed from the hierarchy.

    I'm not saying that your current approach is bad. But sometimes it's worth the effort to step back and replace a system that's overly complex or hard to maintain with something more manageable in the long run.

    One other thing to consider about the hierarchy system: it doesn't support loops. So if you need looped chains, like in the image below - you’ll have to connect all Moleks directly to Chemic.

    In that case, when any Molek is removed, you'll need to check which Moleks are still connected to Chemic and rebuild the hierarchy accordingly.

  • One other thing to consider about the hierarchy system: it doesn't support loops. So if you need looped chains, like in the image below - you’ll have to connect all Moleks directly to Chemic.

    In that case, when any Molek is removed, you'll need to check which Moleks are still connected to Chemic and rebuild the hierarchy accordingly.

    Good to know! Looks like I'll have to do that to support loops. Still, building a dictionary from hierarchy... how would I go about doing this?

  • Here is an example:

    Chemic pick children Molek
    For each Molek
    ... Dictionary add key Molek.dx & "," & Molek.dy
    
  • Here is an example:

    > Chemic pick children Molek
    For each Molek
    ... Dictionary add key Molek.dx & "," & Molek.dy
    

    I just realized I had a line similar to this, and added the add key line in the end. I'm assuming it needed a value of 1 so that's what I put down.

    What's next?

  • I just realized I had a line similar to this, and added the add key line in the end. I'm assuming it needed a value of 1 so that's what I put down.

    What's next?

    This is what I put down underneath the main clause that breaks the chain visually, but so far it does nothing. Is there anything here I'm missing? Or might I be missing something somewhere else?

  • Molek On Destroyed condition picks only one molek instance - the one being destroyed. If you need to process other instances in a sub-event, you need to add "Pick all Molek" as the top condition. Be aware, that the original instance is not completely destroyed yet at this point! So the "For each" loop will process it too, unless you exclude it somehow or wait till the end of the tick.

    So the easiest fix is this:

    + Molek: On destroyed -> Wait 0 seconds
    ----+ System: Pick all Molek
    ----+ System: For each Molek
    
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So the easiest fix is this:

    > + Molek: On destroyed -> Wait 0 seconds
    ----+ System: Pick all Molek
    ----+ System: For each Molek
    
    

    That works... too well. Lol Now I'm having instances of molek fly off that are part of other chains.

    How would I be able to isolate only the affected chain, what in the conditions below would I have to amend/add?

  • I'm not sure I can answer your question. Your game is pretty complex, and while switching to hierarchies has probably made things a bit cleaner and more organized, it's still a complex system.

    All I can do is share how I would probably approach this task:

    1. Pick all moleks that are still in the hierarchy (i.e. children of Chemic). First, set attached = false for all of them.
    2. For each molek in the hierarchy that is directly overlapping (touching) Chemic: set attached = true.
    3. For each molek in the hierarchy with attached=false: check if it’s overlapping another molek with attached=true. If so, change its attached to true. (You might need to use a family: “Molek is overlapping MolekFamily.”)
    4. Repeat previous step until none such moleks left.
    5. Any remaining moleks in the hierarchy that still have attached=false at this point have broken off from the chain. Remove them from the hierarchy and launch them away.
Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)