What does NaN mean?

Get help using Construct 2

Post » Mon Feb 23, 2015 12:14 am

I made a high score system following a tutorial but when i test it, it says NaN where the high score is suppose to be. Anyone know what that means and how to fix it?
B
12
S
3
Posts: 129
Reputation: 1,131

Post » Mon Feb 23, 2015 12:22 am

It stands for "Not a Number", implying that your high scores are invalid numbers. Which tutorial were you following? It's possible that the source of your high scores lacks actual score information, or has numbers represented as strings.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,096

Post » Mon Feb 23, 2015 12:35 am

I don't have enough reputation to post a link but it was the Arcade Style High Score in the Scirra tutorials.
B
12
S
3
Posts: 129
Reputation: 1,131

Post » Mon Feb 23, 2015 11:53 am

NaN is usually the result of unrepresentable mathematical calculations, like sqrt(-1), division by zero, etc. So check your expressions are right.
Scirra Founder
B
383
S
225
G
86
Posts: 24,118
Reputation: 190,544

Post » Mon Feb 23, 2015 12:17 pm

It's also an indian flat bread.
B
12
S
7
G
7
Posts: 448
Reputation: 4,272

Post » Mon Feb 23, 2015 12:26 pm

Coin-coin le Canapin wrote:It's also an indian flat bread.

That bread has double-a's, though :) At least in English.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Tue Feb 24, 2015 12:08 am

I didn't find anything wrong with it, but here's what my events look like.

WebStorage: Local Key "HighScore" exists: System: Set HighScore to WebStorage.LocalValue(HighScore)
System: Else: Set HighScore to 0

System: Score>HighScore: WebStorage: Set Local Key "HighScore" to Score

System: WebStorage: Local Key "HighScore" exists: System: Set HighScore WebStorage.LocalValue(HighScore)
highscore: Set text to "High Score" & HighScore

System: Else: System: Set HighScore to 0
highscore: Set text to "High Score" and HighScore
B
12
S
3
Posts: 129
Reputation: 1,131

Post » Tue Feb 24, 2015 12:39 am

you could try wrapping the high score call in an int() function which turns it back into a number..

int(HighScore) or int(WebStorage.LocalValue(HighScore) should convert it into a proper number if it's thinking it's a string.
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 376
Reputation: 4,854

Post » Tue Feb 24, 2015 3:58 am

Coin-coin le Canapin wrote:It's also an indian flat bread.

LOL
B
54
S
14
G
13
Posts: 819
Reputation: 17,461

Post » Tue Feb 24, 2015 11:44 am

firezombie444 wrote:WebStorage: Local Key "HighScore" exists: System: Set HighScore to WebStorage.LocalValue(HighScore)

You're making a mistake that the WebStorage manual entry warns about:

Note WebStorage only stores strings. If you set a key to a number like 100, when you retrieve it back it will be a string. To convert it back, use the system expression int, e.g. int(WebStorage.LocalValue("score")).
Scirra Founder
B
383
S
225
G
86
Posts: 24,118
Reputation: 190,544

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests