Hundreds of features to explore
Games made in Construct
Your questions answered
Trusted by schools and universities worldwide
Free education resources to use in the classroom
Students do not need accounts with us
What we believe
We are in this together
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
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 ?
p.s I think it's becouse of localstorage...
may be you have set "Type" to text instead of number
You could do a variable check:
if yourVariable*0≠0 then set yourVariable to 0
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:
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)[/code:3f4i0lfn]
I also do the following check for if the item already exists and save it to a global variable:
[code:3f4i0lfn]Local Storage|On item exists: set global variable "yourGlobalVariable" to LocalStorage.ItemValue[/code:3f4i0lfn]
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.
Woah mate, that is a smart one !!!! )))) Good job with that (if works ) [i'll try it...].
Mine is kinda same :
Start -> check Localstorage 'variable' exists.
on variable exist -> get it...
on variable get ->set variable to Localstorage.value.
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
Just noticed that there is also a System event: General: Is number a NaN
Try using int(LocalStorage.ItemValue) when setting a variable after retrieving a value from LocalStorage
Develop games in your browser. Powerful, performant & highly capable.
Thank you for the help guys.