Associating two instances from the editor

Get help using Construct 2

Post » Mon Oct 07, 2013 6:30 pm

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!
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Mon Oct 07, 2013 10:14 pm

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.
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Mon Oct 07, 2013 10:50 pm

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.
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Mon Oct 07, 2013 11:51 pm

If the bucket is always associated with the same gate then simply pick object by UID. It can't really go wrong : D
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Tue Oct 08, 2013 12:14 am

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?
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Tue Oct 08, 2013 12:19 am

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)
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Tue Oct 08, 2013 12:33 am

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?
B
11
S
2
Posts: 87
Reputation: 1,112

Post » Tue Oct 08, 2013 12:39 am

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.
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Tue Oct 08, 2013 12:50 am

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!
B
11
S
2
Posts: 87
Reputation: 1,112


Return to How do I....?

Who is online

Users browsing this forum: Lancifer and 11 guests