How do I inspect collided with object variable before action

Get help using Construct 2

Post » Sat Dec 19, 2015 12:10 am

I need to perform an action when an Enemy collides with another enemy only if the other enemy has a property set to 1.

if I was writing code it would be something like:

Code: Select all
void OnCollisionWith<Enemy>(Enemy enemy){
  if(enemy.Property ==  true){
      doSomething();
}

return;
}


does that make sense?

something like this...
Image
B
8
S
3
Posts: 16
Reputation: 702

Post » Sat Dec 19, 2015 12:14 am

Just add another condition. AND is the default, unless you make an or or else block.
Follow my CZero development on twitter https://twitter.com/CaptainZeroGame
B
62
S
17
G
5
Posts: 171
Reputation: 8,329

Post » Sat Dec 19, 2015 12:14 am

If the event isn't true if the first instance has the variable set to 1, a "system pick nth instance" condition before the check should work for this..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 19, 2015 12:24 am

@Sinistar99 additing another condition inspects the value of the colliding enemy... I need to inspect the collided with enemy
Image <-- this no workie! :(
B
8
S
3
Posts: 16
Reputation: 702

Post » Sat Dec 19, 2015 12:32 am

@LittleStain - I don't see how this can work.
B
8
S
3
Posts: 16
Reputation: 702

Post » Sat Dec 19, 2015 12:37 am

The framework is smart enough when using different object types, but not when using same object types...

If I wrote this - it would work properly. I connected the same instances...
Image

But this is how it behaves when using the same types..
Image

I need this:
Image

Does this illustrate my challenge a bit better?
B
8
S
3
Posts: 16
Reputation: 702

Post » Sat Dec 19, 2015 1:13 am

Hmm sounds challenging
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Sat Dec 19, 2015 1:14 am

Like I said, to differentiate between the two colliding objects you use subevents with the "system pick nth instance"-condition..

Like the manual says:

Pick Nth instance
Pick the instance at a given place in the internal list of picked objects. This is most useful used in sub-events to act on separate instances. For example, in a "Sprite collided with Sprite" event, Pick 0th instance and Pick 1st instance can be used to act on each instance involved in the collision separately.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 19, 2015 1:24 am

I've not made use of this before but I think I will be doing now, looks useful. Seems nth instance 1 works for this scenario.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Mon Jan 04, 2016 4:27 am

You're trying to make an event for an object colliding with the same type.

This is not super intuitive because of the way events work to narrow down objects within a type or family.

Try this:

Make a family called "Enemies" and put ONLY THAT enemy in it. Now make your event

Enemy on collision with Enemies
and
Enemies explode = 1

==> Enemies.destroy
Follow my CZero development on twitter https://twitter.com/CaptainZeroGame
B
62
S
17
G
5
Posts: 171
Reputation: 8,329


Return to How do I....?

Who is online

Users browsing this forum: Fradno, Yahoo [Bot] and 18 guests