How do you store localstorage data?

Hi,

I am making a game where the user enters a username and I want to store this username (as a string). What is the best way to store that?

I have a JavaScript background so I would normally use localstorage but what is the proper way to do so in Lua? To set and get data.

Cheers,

Eli

  1. Save the data in a table.

  2. Encode the table as json.

  3. Save the json to a file.
     
    Later…
     

  4. Read the json content from the file

  5. Decode the data from json into a table

  6. Access the fields you desire.
     
    Here is a tutorial: https://docs.coronalabs.com/tutorial/data/jsonSaveLoad/index.html
     
    SSK2has this functionality built-in.
     
    Above steps using SSK2 (table extensions):
     
     

    –Once only at top of main.lua: require “ssk2.loadSSK” _G.ssk.init( ) – … then later it is easy peasy lemon squeezy – Step #1 local users = {} user[1] = { name = “Bob”, age = 21 } user[2] = { name = “Bill”, age = 25 } – Step #2+3 table.save( users, “users.json” ) --table.prettySave( users, “users.json” ) – Human readable (easier to hand edit if you need)   – Then later… Step #4+5 local users = table.load( “users.json” ) – Step #6 print( users[1].name, users[1].age)

Please peruse all the titles for guides and tutorials.

  1. Save the data in a table.

  2. Encode the table as json.

  3. Save the json to a file.
     
    Later…
     

  4. Read the json content from the file

  5. Decode the data from json into a table

  6. Access the fields you desire.
     
    Here is a tutorial: https://docs.coronalabs.com/tutorial/data/jsonSaveLoad/index.html
     
    SSK2has this functionality built-in.
     
    Above steps using SSK2 (table extensions):
     
     

    –Once only at top of main.lua: require “ssk2.loadSSK” _G.ssk.init( ) – … then later it is easy peasy lemon squeezy – Step #1 local users = {} user[1] = { name = “Bob”, age = 21 } user[2] = { name = “Bill”, age = 25 } – Step #2+3 table.save( users, “users.json” ) --table.prettySave( users, “users.json” ) – Human readable (easier to hand edit if you need)   – Then later… Step #4+5 local users = table.load( “users.json” ) – Step #6 print( users[1].name, users[1].age)

Please peruse all the titles for guides and tutorials.