Uniquely pick only one each of three objects in sub event

Discussion and feedback on Construct 2

Post » Tue Jan 19, 2016 3:46 am

I have a strange issue with multiple sets of objects interacting with each other.

I have two objects, let's call them ObjA and ObjB, which are part of a pair. ObjA keeps a reference to ObjB's UID. There are multiple pairs of ObjA and ObjB scattered throughout the layout.

I also have several of another object, let's call it Marker. A pair of ObjA/B are supposed to perform specific actions together when ObjA collides with Marker. The trouble is, it seems that EVERY pair of ObjA/B will perform this action when one touches a Marker. If I delete all but one pair, the remaining one behaves as expected.

This is my code (approximately):

- On ObjA collision with Marker + Pick instance of ObjB by UID stored in ObjA:
- - If Marker.variable = 1: ObjA do thing 1; ObjB do thing 2
- - If Marker.variable = 2: ObjA do thing 3; ObjB do thing 4

Expected: One ObjA touches a Marker and does its thing 1, while its attached ObjB does its own matching thing 2.
Result: One ObjA touches a Marker and EVERY ObjA does thing 1, and EVERY ObjB does thing 2.

How do I ensure that only the ObjA and ObjB uniquely picked at the top are the objects selected in sub events?
B
10
S
2
Posts: 104
Reputation: 1,140

Post » Tue Jan 19, 2016 4:08 am

Create an instance variable (boolean) for ObjA called 'hit_marker'. When an ObjA hit a marker, set 'hit_marker' to true.
Now you can pick ObjA that is 'hit_marker' to do certain actions.

In your stated approach, no ObjA being clearly filtered because the reference is the Marker not ObjA UID or IID.
ImageImage
B
111
S
51
G
24
Posts: 786
Reputation: 23,392

Post » Tue Jan 19, 2016 4:19 am

- On ObjA collision with Marker + Pick instance of ObjB by UID stored in ObjA:
- - If Marker.variable = 1: ObjA do thing 1; ObjB do thing 2
- - If Marker.variable = 2: ObjA do thing 3; ObjB do thing 4

As typed it should act exactly like your expected result. If it doesn't there must be some other events effecting it.

Can you show an image of your event or maybe a capx.

Edit:
@alextro
Doesn't the on collision event pick both the ObjA and Marker? I guess I'd have to test it but I haven't had to do something like that as I recall.
B
94
S
33
G
113
Posts: 5,354
Reputation: 73,269

Post » Tue Jan 19, 2016 5:44 am

@R0J0hound
Ah you are right... sub-event. I didn't see the indentation.
However In my experience it always better to lock a state by using boolean to make something obvious and easy to trace.

@MoscowModder
Try to add 'for each' ObjA to force a system to recognize the condition.
ImageImage
B
111
S
51
G
24
Posts: 786
Reputation: 23,392

Post » Tue Jan 19, 2016 1:47 pm

I don't see how a for each condition would help - I only want it to happen to one pair of the objects.

Here's a screenshot:
Image
Claw = ObjA; Claw_Top = ObjB; CutscenePoint = Marker
B
10
S
2
Posts: 104
Reputation: 1,140

Post » Tue Jan 19, 2016 7:20 pm

Nothing looks out of the ordinary, it should work. I'm guessing the event isn't a sub-event of something. I'd still say that something else is going on like some other event causing all the claws to collide with the cutscenePoint or something. Of course that's just speculation.

I guess the next step would be the capx or a simplified version of it with the same issue. That way we have something to work with and find the cause.
B
94
S
33
G
113
Posts: 5,354
Reputation: 73,269

Post » Wed Jan 20, 2016 1:32 pm

Turns out you were on the right track, R0J0 - the very next event after the screenshot did something similar but picked Claw_Top where UID equals Claw.ClawTopUID. I swapped that out for a pick by unique ID, and the problem was solved. Thanks for the tips, people!
B
10
S
2
Posts: 104
Reputation: 1,140


Return to Construct 2 General

Who is online

Users browsing this forum: BlueAlfie and 5 guests