Global variable taking junk values

0 favourites
  • 10 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.
  • Hi,

    In my game I am using a global variable for scoring named "Score". Everytime a collision event occurs "Score" should increase by 1. But when I run the game the variable gets set to random values everytime collision event occurs.

    Attaching screenshot. Please help.

  • I'm not positive about this, but it might be that its reading more than one collision each time it hits.

    Can you put in a "trigger once while true" condition?

    I'm not certain that will fix it.

    It also seems like collision always works best if you have a perfect rectangle hitting another perfect rectangle.

    Hope that helps, but its likely another issue.

  • Oh sorry. It probably isn't that, because you're destroying the ball as soon as it hits.

    Maybe worth a try still.

  • We have too few information to answer your question, imo.

    Does score appear anywhere else in your code?

    What is meant with random values - which numbers are you seing? Are the differences only small or are you getting huge, unrealistic numbers?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Score only appears at above shown location in my code. It takes random values on collision like -

    2,12,17, 37,54

    4, 11,29,35

    Tried the "trigger once condition" but it didnt work.

  • You need to post your code. The numbers are all incrementing, so you are getting multiple hits.

  • It's possible that your bullet is colliding with multiple wall objects at the same time, so the event is running for each collision. There's some strange behavior to be aware of when you destroy an object -- relating to when it actually ceases to exist -- but I don't remember what it is off the top of my head.

  • Colliding with multiple walls at the same time is most likely. You probably don't want multiple walls stacked onto each other for performance issues, but to solve the problem you can set an instance variable to mark whether the ball has been "scored" and check that before adding score. That way only the first collision will add to the score for that ball.

    Something like:

    On collision and ball scored = 0: Set ball scored to 1, add 1 to Score, set text to Score and Destroy ball.

  • Thanks tgfcoder. That worked

  • hgambhir

    could you please tell me how you solve that with steps

    i'm facing the same problem

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