"NaN" result....

  • I have a 2 Globals that I divide into each other to give me a "Ratio(Hit vs Shot Fired)" if you will.

    When there has been NO activity, the Text box for the Ratio shows up as "NaN".

    How do I make this show "0" until I have a positive figure for it?

    I've tried Compare variable if less/equal to 0 then set text to 0, but that still results in "NaN"

    Thanks in advance for any help on this.

  • Well, the easiest way is setup conditionals to make the divisor always bigger than 0, NaN is "Not a Number", if you're doing a division by 0, it's infinite, and will never converge to a number.

  • Well, it works great otherwise. The only problem is with the Initial launch of the game. If you've never played before, then you have no stats to compare.

    It's on the Stats screen where this is happening, I just want it to read "0" till they play the game at least once.

    I may just Set Text to "0" until it's > than 0, idk. i'll play with it abit more.

    Thanks for the thoughts!

  • If the divisor is 0, set the output to 0. Otherwise if the divisor is not 0, do the division.

  • TELLES0808

    dividing by zero isn't infinite. It's undefined. But yeah, javascript wrongly returns Infinite (should return NaN or undefined).

    Subscribe to Construct videos now

    (:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you Yann, always learning =]

  • Thanks Guys. I do understand the process better now. All I had to do though was move each individual calculation under it's proper "difficulty" group and it worked out great.

    But i truly did not fully understand how it worked till you guys explained it.

    Thanks again!

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