- Joined
- Jul 17, 2017
- Messages
- 76
I've put together a (very) small module that gives access to saving and loading from LocalStorage on the html5 target. It's similar to the existing SaveState, but you can specify your own key/value pairs instead of needing to have it be one long string. It's about as close as you can get to being able to save things to disk for html5.
Repo with example: https://github.com/wickworks/localstorage
localstorage.cxs
native/localstorage.js
(This is the first time I've managed to get Extern working to run javascript code! It wasn't as hard as I was afraid it would be.)
Repo with example: https://github.com/wickworks/localstorage
localstorage.cxs
Code:
#If TARGET="html5"
Import "native/localstorage.js"
#Else
#Error "The localstorage module is only available on the html5 target"
#Endif
Extern
Function SaveLocalStorage(key:String, value:String)
Function LoadLocalStorage(key:String)
native/localstorage.js
Code:
SaveLocalStorage = function(key, value) {
localStorage.setItem(key, value); //key can't start with dot in Chrome!
return 1;
}
LoadLocalStorage = function(key) {
var state = localStorage.getItem(key);
if (state) return state;
return "";
}
(This is the first time I've managed to get Extern working to run javascript code! It wasn't as hard as I was afraid it would be.)