Load tiled map from a .json table

Hi. Does anyone know if it would be possible to load a tiled map with a variable connecting to a .json table?

I have transformed this script but I get an error with the directory:

game.lua

 local filename = event.params.map or "scene/game/map/game.json" local mapData = json.decodeFile( system.pathForFile( filename, system.ResourceDirectory ) ) map = tiled.new( mapData, "scene/game/map" )

I try to call the filename of game.json to load sandbox3.json

game.json

{"filename":"scene/game/map/sandbox3.json"}

… what I try is that by colliding hero with an object on any screen, I save the screen, (for example, sandBox3.json) and then be able to restart the game on that screen by calling the filename table.

I would load it like this:

local json = require( "json" ) local loadsave = require("loadsave") local gameSettings = { filename = "scene/game/map/sandbox3.json", } loadsave.saveTable( gameSettings, "game.json" ) --but in this directory: scene/game/map/game.json"

Greetings, I hope you have explained me well

Well … in the end I solved it, thanks to the topic of kaylabrownph22: https://forums.coronalabs.com/topic/74381-save-and-load-levels-in-the-sticker-knight-game/

The approach of kaylabrownph22 is good, but it has an error, I have replaced map with variable level:

keeping level:

local s = {} s.level = self.map loadsave.saveTable(s, "game.json", system.DocumentsDirectory)

it is saved in game.json:

{"level":"scene/game/map/sandbox2.json"}

and I insert it in game.lua:

local s = {} s = loadsave.loadTable("game.json", system.DocumentsDirectory) local filename = s.level local mapData = json.decodeFile( system.pathForFile( filename ) ) map = tiled.new( mapData, "scene/game/map" )

Regards

Well … in the end I solved it, thanks to the topic of kaylabrownph22: https://forums.coronalabs.com/topic/74381-save-and-load-levels-in-the-sticker-knight-game/

The approach of kaylabrownph22 is good, but it has an error, I have replaced map with variable level:

keeping level:

local s = {} s.level = self.map loadsave.saveTable(s, "game.json", system.DocumentsDirectory)

it is saved in game.json:

{"level":"scene/game/map/sandbox2.json"}

and I insert it in game.lua:

local s = {} s = loadsave.loadTable("game.json", system.DocumentsDirectory) local filename = s.level local mapData = json.decodeFile( system.pathForFile( filename ) ) map = tiled.new( mapData, "scene/game/map" )

Regards