how to work with a pre-existing number

hello , i’m a newbie of lua language and i want to ask a silly question. I’m making a simple tool that keeps track of a number and there are 3 buttons :
i want to change the number in real time and once closed the app , next time i open it, it should start from the number of previous session ( e.g if i, reach let’s say, 55 by pressing those 3 buttons ,once re-opened i want to start from 55 to change the number upward or downward ) right now i’m using a Hihgscore type system that just don’t fit very well.

Hi, you can save the number and then get it when needed:

-- saving
local function save(baseDir,fileName,srcTable)
   baseDir  = baseDir or system.DocumentsDirectory

   local encodedTable = json.encode( srcTable )

   io.writeFile( encodedTable, fileName, baseDir )

   return encodedTable

--getting data 
local function load(baseDir,fileName)
   baseDir  = baseDir or system.DocumentsDirectory

   local encodedData = io.readFile( fileName, baseDir )

   local restoredTable = json.decode(encodedTable)

   return restoredTable

How to use it:

-- saving data

local myTable = {
  num = 12,

-- getting data


And I think you will need these modules: just put folder into your app/game folder and type this in you main.lua (or scene file):

require ""
require "extensions.string"
require "extensions.table"

[ (8.4 KB) ](http://)

And these modules are not mine, @roaminggamer gave me these.

1 Like

More details on the extenstions:

Source for all of SSK2:


thank you both very much