espace Posted November 18, 2017 Share Posted November 18, 2017 hi, I use this function to to set the storage : var logic_position=function(sprite){ if (debug_position){ hero.grid.visible=false ; var _table; var _name_json; switch(sprite.name){ case 'canon': _table=c; _name_json='canon'; _table[sprite.number] = { number:sprite.number, delay:Math.round(sprite.delay), x:Math.round(sprite.x), y:Math.round(sprite.y), speed:Math.round(sprite.speed), frequency:Math.round(sprite.frequency), variance:Math.round(sprite.variance), angular:Math.round(sprite.angular), _flag:sprite._flag, kill_with_world:sprite.kill_with_world, special_color:sprite.special_color, _rotate:sprite._rotate, _value_rotate:sprite._value_rotate, }; break; } this.level=level_number; this.name_level='lev'; this.combined_level=this.name_level+this.level; localStorage.setItem(_name_json+sprite.number+this.combined_level, JSON.stringify(_table[sprite.number]),null,"\t"); } }; console.log(localStorage) The result of the localStorage is this : { "canon0lev0": "{\"number\":0,\"delay\":0,\"x\":200,\"y\":840,\"speed\":2000,\"frequency\":60,\"variance\":20,\"angular\":180,\"_flag\":false,\"kill_with_world\":true,\"special_color\":false,\"_rotate\":false,\"_value_rotate\":10}" } And what i want is this : { canon0lev0:{ number:0, delay:0, x:200, y:840, speed:2000, frequency:60, variance:20, angular:180, _flag:false, kill_with_world:true, special_color:false, _rotate:false, _value_rotate:10} } } However i follow this link to format my json but it's not the result expected https://stackoverflow.com/questions/2614862/how-can-i-beautify-json-programmatically What i must do to have the result expected... Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 18, 2017 Share Posted November 18, 2017 Why would you ever want to store extra bytes into local storage? Just stringify it `JSON.stringify({foo: 'bar'})` on the way in and parse it on the way out, don't worry about making local storage formatted, totally pointless. Quote Link to comment Share on other sites More sharing options...
espace Posted November 18, 2017 Author Share Posted November 18, 2017 Because I have developed an editor to configure my levels. I use dat.gui and I could publish the parameters of my enemies to my email. What I doesn't understand is why I have this syntax : \"parameter"\ Quote Link to comment Share on other sites More sharing options...
espace Posted November 18, 2017 Author Share Posted November 18, 2017 ok i understand what you mean => as we say the coin is fall => problem solved thanks mattstyles 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.