Associating two instances from the editor

0 favourites
  • 9 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • I'm trying to figure out the best way to associate two instances of two different objects in the editor. Basically it's a lock-and-door situation, I have a gate and a bucket (put a certain number of things in the bucket to open the gate). I want to be able to easily get the associated bucket if I pick a gate and vice versa.

    Containers won't work for me for a number of reasons:

    • All gates have buckets but not necessarily all buckets have gates
    • I want to be able to associate the two objects from the editor since placements will vary and there are multiple bucket/gate instance pairs
    • both object types already have containers for other purposes and so can't be added to each other's containers anyway

    I have a number of ideas for solutions but would like opinions on what might be the best course (or ideas for solutions that I'm missing). Please let me know what you think!

    1. UIDs as instance variables (so the bucket object has a gateID and the gate object has a bucketID and I enter UIDs manually). The problem here is just the overhead of having to enter and potentially update UIDs, and the errors that might result if I clone a pair and forget to update their instance variables

    2. Use "Pick Nearest" to get the closest bucket to a gate. Works in theory as long as I always keep buckets next to their gates, but breaks down if there ever comes a case where this isn't true (or if two bucket/gate pairs happen to be near each other and might mess this up).

    3. Create a "linker" sprite that I drag over both bucket and gate, and use overlapping checks to see which objects are overlapping the same linker. Might be unwise to add unnecessary collision checks.

    4. A combination of 3 and 1, where I do one collision check at the beginning of the layout to set up the instance variables and then use UID picking elsewhere in the event sheets.

    If you have any thoughts on these or better ideas for ways to solve this, please let me know. Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Are you actually able to access more than one gate and/or bucket at the same time? If not, then I don't think any of this is needed. When items collide with a bucket you add numbers to an instance variable for the bucket and then enable gate opening.

  • But how do I pick which gate opens? There are multiple bucket gate pairs in the layout, so i need to be able to pick the gate that is associated with the bucket.

  • If the bucket is always associated with the same gate then simply pick object by UID. It can't really go wrong : D

  • Well, yes, but the question is HOW do I associate the bucket with the gate. Do I take it you mean that options 1 and 4 in my solutions are the best ones?

  • My favourite way would be :

    If Bucket = Full (instance variable Full set to true perhaps)

    Cond: Pick bucket by unique ID (ID of relevant bucket)

        Sub event: Pick gate by unique ID (ID of related gate)

                  Do Action (like move gate, play anim of gate whatever it is you're doing)

  • I think we're having a miscommunication here. I see what you mean about picking the relevant ID's of the bucket/gate.

    My question is. HOW do you know what ID to pick?

    So in this step

    Cond: Pick bucket by unique ID (ID of relevant bucket)

    How do I know (ID of relevant bucket)? Where is that previously set and how?

  • Ah ok, from the way you listed the ways of doing it I assumed you knew what UIDs were. When you select the object, the UID is listed on the left side under the name of the object. In the kind of game you're describing I think it's fine to just use UIDs as you are unlikely to be spawning and destroying loads of buckets and gates etc.

  • Yes, I do know what UIDs were. Okay, so I understand now that you are suggesting I do #1 on my list - manually entering UIDs as instance variables for all the buckets/gates. Communication resolved!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)