How do I check if a variable is Nan ?

Get help using Construct 2

Post » Mon Apr 17, 2017 11:11 am

Hi,
It keeps saying me that 'x' variable is Nan, I checked everything, didn't find a problem..
Can i bypass it somehow ? Can i check if x is nan -> set x 0 ?
Thank you,
p.s I think it's becouse of localstorage...
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Mon Apr 17, 2017 11:46 am

may be you have set "Type" to text instead of number
Image
B
72
S
41
G
48
Posts: 687
Reputation: 34,290

Post » Mon Apr 17, 2017 12:02 pm

You could do a variable check:

if yourVariable*0≠0 then set yourVariable to 0
B
64
S
25
G
10
Posts: 654
Reputation: 10,842

Post » Mon Apr 17, 2017 2:17 pm

Ah, I've had something similar happen with local storage - you need to make sure the local storage variable is created and has a value before you can do anything with it, otherwise it will register as Nan.

This is how I set it up, at the start of the main event sheet:

Code: Select all
System|On start of layout: Local Storage|check item "yourLSVariable" exists
Local Storage|On item missing: Local Storage|set item "yourLSVariable" to (whatever value you want)


I also do the following check for if the item already exists and save it to a global variable:

Code: Select all
Local Storage|On item exists: set global variable "yourGlobalVariable" to LocalStorage.ItemValue


I can then work off the global variable instead of referring to the LocalStorage. At the end of the session I can then save that global back our to local storage if needed.

Another related tip - avoid putting any local storage events on a Loader layout, if you have one; I believe that once the game has downloaded once, the loader layout doesn't always play, in which case it would skip all those events.
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Mon Apr 17, 2017 3:18 pm

@Elliott
Woah mate, that is a smart one !!!! :))))) Good job with that (if works ) [i'll try it...].

@mekonbekon
Mine is kinda same :

Start -> check Localstorage 'variable' exists.
on variable exist -> get it...
on variable get ->set variable to Localstorage.value.
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Mon Apr 17, 2017 3:19 pm

@Elliott
@mekonbekon
@luckyrawatlucky

Thank you for answering me, the simplest & fastest answer was Eliot's one.
He deserves a big beer, very very very smart my friend, thank you ;) (y) good job
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Mon Apr 17, 2017 3:51 pm

@Radulepy

Just noticed that there is also a System event: General: Is number a NaN :)
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Mon Apr 17, 2017 7:25 pm

@Radulepy

Try using int(LocalStorage.ItemValue) when setting a variable after retrieving a value from LocalStorage
Find all the Construct 2 games that were on Steam Greenlight here
B
36
S
10
G
7
Posts: 477
Reputation: 7,019

Post » Thu Apr 20, 2017 3:58 pm

@OddConfection
@mekonbekon
Thank you for the help guys.
B
11
S
3
Posts: 277
Reputation: 1,395


Return to How do I....?

Who is online

Users browsing this forum: dop2000, WanderingHatred and 8 guests