How do I increment a global variable two times on same tick

Get help using Construct 2

Post » Sat May 07, 2016 3:05 pm

Message: dondosh can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I'm trying to do a 100 balls game like and I struggle with one problem.

I have an event that is:
BasketTrigger Is overlapping Ball :
-> System Add 1 to score
-> Destroy Ball


Image
Ball are the blue balls
BasketTrigger is the grey box
score is a global variable

I'm not sure, but I think the problem is that if two Ball hit the BasketTrigger at the same time, they increment the same value.
What I mean is that imagine score variable is at 10:

On the same tick, two Ball overlap with BasketTrigger so the system will do 10+1 for the first Ball event and since it happen at the same time the second Ball event doesn't know that score variable is at 11.

So the score variable will be 11, but it should be 12.

Can I do something different to make it work ? I use physics too, if it matter.

Link to my capx file (I don't have enough rep to post link so just copy paste next two line in address bar):
https://www.
dropbox.com/s/6inhgqanbo1fe5t/100balls-clone.capx?dl=0

Thanks!
B
10
S
4
G
6
Posts: 26
Reputation: 3,790

Post » Sat May 07, 2016 3:29 pm

Hello,

Your event "Is BasketTrigger overlapping Ball" is not set by instances, and only triggers the first of all the balls that overlap in the same tick.
So you have to change it to :
- For each Balls
- is Ball overlapping with BasketTrigger
- Add 1 to score

Like in this : https://www.dropbox.com/s/zpe3495i84iz1uc/100balls-clone-fixed.capx?dl=0
Last edited by Nabu0001 on Sat May 07, 2016 3:30 pm, edited 1 time in total.
B
14
S
4
Posts: 109
Reputation: 1,281

Post » Sat May 07, 2016 3:29 pm

In event 6, the two balls are picked, so you either have to add a "For each Sprite3", or instead "Add Sprite3.PickedCount".
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sat May 07, 2016 4:15 pm

Thanks it works like a charm !
B
10
S
4
G
6
Posts: 26
Reputation: 3,790


Return to How do I....?

Who is online

Users browsing this forum: amkp, sublimate and 10 guests