Global variable set to NaN?

Get help using Construct 2

Post » Thu May 29, 2014 8:32 pm

Hi guys,

My layout starts and creates a bunch of global variables. The last of which is instead of setting to 0 is being set to NaN.

Anybody know what this is and how to stop it?
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542

Post » Thu May 29, 2014 8:40 pm

...and before you ask the only time the value is set is when it is created i.e. Global number variable1 = 0
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542

Post » Thu May 29, 2014 9:02 pm

NaN means Not a Number. You will want to make sure the 0 is not "0". If it's wrapped in quotes, Construct would try to store a text value, not a number value. Hence the NaN result.

If that is not the case, I would have to look at your capx to help further.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Thu May 29, 2014 9:17 pm

I found your previous topic and downloaded your file. When I run it, I see both layouts counting up at the same rate. Starting on layout 1, the text begins counting, when I swapped to 2 it takes up the count right where I left off. I don't see the NaN result. I ran it in Chrome, FF and IE11. It ran fine in all 3. What browser are you using?
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Thu May 29, 2014 10:12 pm

@FragFather

I understand you get a NaN when setting a string to a number. However, I am not doing that. The only time the value is set is when the global is declared with a default value of 0. What is interesting is the second time I run the layout, i.e. title screen to game back to title screen, It is no longer a NaN and set to 0.

The capx was something I created instead of providing my whole project. It wasn't the problem I thought it was and that capx proved it. After debugging I found that the last global variable in my layout was returning a NaN. On the second time the layout ran it returned 0.
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542

Post » Thu May 29, 2014 10:26 pm

I made a new variable called GlobalFullVersion and used that instead. It must not like the variable name GlobalUnlocked.

Very strange
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 21 guests