Hi everyone.
At the start of the game, I'm loading settings parameters from a json file. If the file is not present, then the file is created and then loaded. I'm using the datasaver module from
github. Now the process works fine on the mobile version but doesn't seem to work on desktop. I've tried using both firefox and chrome. This has completely stumped me.
Any and all help deeply appreciated.
Comments
You just need to add JSON in Plugins.json class:
Then some global variables:
Then create the json file (if it doesn't exist create it)
Note that these are global functions.
And then later in the app save new parameters to the json file:
You can call this function from anywhere in your code.
Hope this help.
That works for me in both android and desktop.
Likes: MoKaLux
there're services with simple api (jsonbin.io, etc)
(but probably they won't help you if you need json for every user)
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
@MoKaLux and @antix - Thanks for providing the code snippets. I'm using something similar too to load and save game preferences which works perfectly on mobile. It's deskptop browser that I'm having trouble too. Like you mentioned @antix, saving data in a browser is pretty difficult.
Anyways, I looked around and apparently saving locally is possible in javascript using the
HTML5 localStorage Object. Any idea as to how that can be implemented using the JS plugin?
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Checking JS as I write this. Thanks for the link.
Likes: MoKaLux
--------------------------------------------------
local platform = string.lower(application:getDeviceInfo())
if platform == "web" and (not mydata.levelselect) then
JS.eval([[
var M = { name: "John", maxLevels: 500, city: "New York" };
localStorage.setItem('favouriteData', JSON.stringify(M));
]])
local data = JS.eval([[ JSON.parse(localStorage.getItem('favouriteData')); ]])
mydata.levelselect = data
--------------------------------------------
mydata.levelselect is showing a nil value.
p.s - How do I post code on this forum?
Likes: MoKaLux
Likes: pm1891
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
local data = JS.eval([[ localStorage.getItem('favouriteData'); ]])
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
on FF it is necessary to write as follows:
window.localStorage;
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Likes: MoKaLux