Confusion on How Event Works ?

Discussion and feedback on Construct 2

Post » Thu Mar 22, 2012 11:52 pm

My brain is fried trying to figure out why this simple event doesn't work as I expected.

So here it goes:
1. Move your red Player with arrow keys to the right.
2. When the red Player overlap with the ShadowCaster, they will spawn a Shadow.
3. When the red Player is not overlap with the ShadowCaster, shadow will be removed from ShadowCaster.

Event works fine when all of the ShadowCaster is not line up in X coordinate:
http://dl.dropbox.com/u/39382262/EventWorks.capx

The exact same event fail when ShadowCaster line up on X coordinate:
http://dl.dropbox.com/u/39382262/EventFail.capx

it will no longer destroy the shadow.
Could someone help me out and explain why this happens ?


ThanksPotato2012-03-22 23:54:22
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri Mar 23, 2012 2:26 am

The problem is with the last condition in the destory shadow event.

"Shadow --> casterID = ShadowCaster.casterID"

disable it and it works fine.

I guess the other instance is and this condition fails.

If you want it to be specific you could store the IID of shadow to an instance variable in the ShadowCaster, and pick Shadow using it.
B
28
S
9
G
6
Posts: 30
Reputation: 6,609

Post » Fri Mar 23, 2012 2:54 am

Thanks Danijerry,

but if i delete the
"Shadow --> casterID = ShadowCaster.casterID"

Then it will destroy all of the shadow, like so:
http://dl.dropbox.com/u/39382262/EventDestroyAll.capx

i thought that condition is in there so that it will only destroy Shadow for ShadowCaster outside of the Player.



When reading the Destroying Shadow event above, i thought these what suppose to happen:

1. Pick all ShadowCaster that's not overlap with the Player
2. Filter again with ShadowCaster that only has Shadow
3. Pick Shadow that have a "casterID" the same as ShadowCaster filtered from step 2. -> Destroy this picked Shadow


hmmm... something is not right

B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri Mar 23, 2012 3:14 am

To clarify the last condition does not go through each of the shadow instead always picks the first instance of the shadow sprite which is the one that is outside the layout which has a casterID of 100. To make this work you may have to go through each shadow using a for loop.

This may be better!

http://dl.dropbox.com/u/28195143/c2_share/Shadow_UsingUID.capxDanijerry2012-03-23 03:31:18
B
28
S
9
G
6
Posts: 30
Reputation: 6,609

Post » Fri Mar 23, 2012 7:46 am

Thanks a lot Danijerry,

now everything start to make sense to me.
I guess i can't rely on comparing instance variable to do the filtering / picking, i'll use a direct UID picking as your example in the future
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri Mar 23, 2012 10:14 am

[QUOTE=Potato]I guess i can't rely on comparing instance variable to do the filtering / picking..[/QUOTE]
Sure you can, used Danijerry's example - download
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Fri Mar 23, 2012 6:24 pm

Thanks Noga, looks like using "for each" work like it was intended.

Now... please check this out, this really blows my mind,
the exact same logic is applied to this Clown Destroying Kid :D
and it works just fine, without even using "For Each".



capx:
http://dl.dropbox.com/u/39382262/ClownDestroyKids.capx

demo:
http://dl.dropbox.com/u/39382262/Clown/index.html

How come it works fine in this case ?

I really need someone to explain how this whole condition thing works
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri Mar 23, 2012 6:37 pm

So what is exactly happens in there, how the condition flows internally ?

Let say, player is overlap with Clown 77 & Clown 12
Does it flow like this:

Kid 13 = Clown 77
Kid 77 = Clown 77 -> Destroy Kid 77
Kid 56 = Clown 77
Kid 56 = Clown 77
Kid 12 = Clown 77
Kid 77 = Clown 77 -> Destroy Kid 77
Kid 80 = Clown 77

Kid 13 = Clown 12
(Kid 77 Already destroyed)
Kid 56 = Clown 12
Kid 56 = Clown 12
Kid 12 = Clown 12 -> Destroy Kid 12
(Kid 77 Already destroyed)
Kid 80 = Clown 12Potato2012-03-23 20:51:15
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri Mar 23, 2012 9:19 pm

Actually thats kinda weird when the condition runs like my post above,
because still using the same example:



Set 1: Kid 13, Kid 77, Kid 56, Kid 56, Kid 12, Kid 77, Kid 80
Let say player is overlapping with Set 2: Clown 77, Clown 12

Action usually run like this:

Kid 13 = Clown 77
Kid 77 = Clown 12
Kid 56 = Clown 77
Kid 56 = Clown 12
Kid 12 = Clown 77
Kid 77 = Clown 12
Kid 80 = Clown 77

and it will not destroy anything since no match happen,
but that's not what happens here, because the event successfully destroy the correct Kid.

Is the way Condition run & Action run is different ?Potato2012-03-23 21:24:58
B
34
S
13
G
8
Posts: 134
Reputation: 8,118

Post » Fri Mar 23, 2012 9:27 pm

For your first problem you just need to destroy the initial shadow.
[code]Start of Layout:
--Shadow| destroy[/code]

The "A is overlapping B" condition filters object A and loops over all the collision pairs with B. An inverted "A is overlapping B" is just a filter for A.

So in event 2:
a. All the ShadowCasters not overlapping the player are selected.
b. Of the selected only the ShadowCasters with "haveShadow" are selected.
c. Now each Shadow.CasterID is compared with ShadowCaster.CasterID with this pattern
1st selected Shadow.CasterID is compared with the 1st selected ShadowCaster.CasterID,
2nd selected with 2nd selected... and so on.


You second example runs like this pseudo code:
[code]
For each clown overlapping player:
if clown havekid:
    select kids with id=clown.id
        destroy selected kids
[/code]
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests