destroy on collision and count objects = bug?

Discussion and feedback on Construct 2

Post » Thu Jul 21, 2016 4:57 pm

I have 6 fruits on screen, and a platform player.

When collisioning with a fruit, I destroy it, and checking to see if the Count is 0. However, I never reach Fruits.count = 0 sub-event when it's nested under the "on collision" trigger. When I put the Fruits.Count = 0 outside (every tick), this works just fine.

Doesn't work (actually the Text value in the trigger is one behind. If I had 6 and destroyed one, it will still show 6):

Image

Works:

Image

Any ideas? Is this expected?
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Thu Jul 21, 2016 5:27 pm

It's expected since when you destroy an object it's not removed till the next toplevel event.
So right below event 25 in the first image, or right below event 23 in the second.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Thu Jul 21, 2016 5:51 pm

Yea @R0j0hound is right. Easiest fix. Create a global variable called "count" or somithing.

On collision
->set Count to 1

in a new top leve event,

Count = 1
-> set text to Fruits.Count
-> set count to 0
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Thu Jul 21, 2016 5:58 pm

Thanks, both of you, bummer I have to create another event at the top instead of its appropriate logic place :(
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Thu Jul 21, 2016 6:29 pm

You don't have to place it at the top of the event sheet. Top-Level event means it's not a sub event.
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Thu Jul 21, 2016 9:10 pm

Fruits.count = 1, works, because the destroy is uncontional.

In fact, it is Fruits.count - 1 = 0, accounting for the not actual destroyd one yet, since it is a sub event.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jul 21, 2016 9:56 pm

@tunepunk, yeah, I meant top level :)
@99Instances2Go, that's cool, already albeit awkward. Question is: can I ABSOLUTELY count on it that it will be 1? I COULD check < 2, so if by any chance it's a 0....
B
18
S
7
G
1
Posts: 157
Reputation: 1,928

Post » Thu Jul 21, 2016 11:30 pm

< 2 is fine for that 1 time on 600 biljon trys it might be zero. Afraid you still dont understand why though, so by next revision of your code it might be 9.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to Construct 2 General

Who is online

Users browsing this forum: adelwich, Yahoo [Bot] and 27 guests