# "NaN" result....

Get help using Construct 2

### » Mon Apr 15, 2013 7:45 pm

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.dooley2013-04-15 19:45:55
B
12
S
2
Posts: 75
Reputation: 2,126

### » Mon Apr 15, 2013 8:16 pm

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.
B
92
S
18
G
12
Posts: 1,166
Reputation: 18,090

### » Mon Apr 15, 2013 10:50 pm

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!
B
12
S
2
Posts: 75
Reputation: 2,126

### » Mon Apr 15, 2013 11:16 pm

If the divisor is 0, set the output to 0. Otherwise if the divisor is not 0, do the division.
Scirra Founder
B
355
S
208
G
71
Posts: 22,832
Reputation: 176,710

### » Mon Apr 15, 2013 11:26 pm

@TELLES0808
dividing by zero isn't infinite. It's undefined. But yeah, javascript wrongly returns Infinite (should return NaN or undefined).
here's explained why (:
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,336

### » Tue Apr 16, 2013 12:55 am

Thank you @Yann, always learning =]
B
92
S
18
G
12
Posts: 1,166
Reputation: 18,090

### » Tue Apr 16, 2013 5:19 am

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!
B
12
S
2
Posts: 75
Reputation: 2,126

### Who is online

Users browsing this forum: MSNbot Media, Yahoo [Bot] and 9 guests