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

0 favourites
  • 4 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • 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

    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):

    dropbox.com/s/6inhgqanbo1fe5t/100balls-clone.capx?dl=0

    Thanks!

  • 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

  • In event 6, the two balls are picked, so you either have to add a "For each Sprite3", or instead "Add Sprite3.PickedCount".

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks it works like a charm !

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)