build 740 and 741- change to json?

Johantd04 did you ever get this sorted? Having similar issues to you with a game we are working on.

We have some objects being saved using ice in a level editor and they are saving fine but when we go retrieve them when loading the level we get an error saying there are no objects to retrieve. It randomly works with some levels but then doesnt with others.

Anyone else have any solutions they got working? [import]uid: 44553 topic_id: 21532 reply_id: 103403[/import]

Hi, the issue seemed to be with Ice so I ended up writing my own code for storing/fetching data.

[code]
– Project: Settings

– Version: 1.0

– Author: Johan Johansson @ Baboons.se

– Support: www.baboons.se

– Copyright © Baboons. All Rights Reserved.

– Require Json
local json = require(“json”)

–Initialize object
local settings = { }

function settings:set(key, value)
self.data[key] = value
self:save()
end

function settings:get(key)
if self.data then
return self.data[key]
else
return nil
end
end

function settings:remove(key)
self.data[key] = nil
end

function settings:increment(key)
local value = self:get(key) or 0

value = value + 1

self.data[key] = value
self:save()
end

function settings:decrement(key)
local value = self:get(key) or 0

value = value - 1

self.data[key] = value
self:save()
end

function settings:hasValue(key)
if self.data then
if self.data[key] then
return true
else
return false
end
else
return false
end
end

function settings:save()
local path = system.pathForFile(self.file, system.DocumentsDirectory)
local fh = io.open(path, “w”)

fh:write(json.encode(self.data))
fh:close()
end

function settings:clear()
for key, value in pairs(self.data) do
self:remove(key)
end

self:save()
end

function settings:load(name, extension)
local extension = extension or ‘json’
local file = name … ‘.’ … extension
local o = { file = file }

local path = system.pathForFile(file, system.DocumentsDirectory)
local fh, reason = io.open(path, “r”)

if fh then
– read all contents of file into a string
local contents = fh:read("*a")

local succ, data = pcall(function()
return json.decode(contents)
end)

if succ then
o.data = data
else
o.data = {}
end
else
– print("Coulnd’t load settings: " … reason)
o.data = {}
end

setmetatable(o, self)
self.__index = self
return o
end

return settings
[/code] [import]uid: 106083 topic_id: 21532 reply_id: 103450[/import]

And then I use it like this (works with multiple setting files)

[code]
– require settings module
local settings = require(“lib.settings”)

– Settings
storyboard.preferences = settings:load( “preferences” )
–storyboard.preferences:clear()
storyboard.preferences:set( “player_id”, “11” )

– States
storyboard.states = settings:load( “states” )
[/code] [import]uid: 106083 topic_id: 21532 reply_id: 103451[/import]

I could kiss you! [import]uid: 6310 topic_id: 21532 reply_id: 135275[/import]

I could kiss you! [import]uid: 6310 topic_id: 21532 reply_id: 135275[/import]