Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Load Background from json — Gideros Forum

Load Background from json

GiderosFanGiderosFan Member
edited June 2015 in General questions
Hello, i've tried to load an background from json level pack is this possible?

my load routine looks like this:
	self.curPack = sets:get("curPack")
	self.curLevel = sets:get("curLevel")
 
	self.level = dataSaver.load("levels/"..self.curPack.."-"..self.curLevel)
	for i, value in ipairs(self.level) do
	if value.type == "backgrounds" then
	local background = Bitmap.new(Texture.new("graphics/value.back", true))
	end
	end
my json level pack file looks like this:

[{"type":"backgrounds","back":back1.png}]

i can't load the right background. everytime i get an error.

this is the error:

classes/json.lua:318: Error reading 'true': [{"type":"backgrounds","back":tile.png}]
stack traceback:
classes/json.lua:318: in function 'TestReservedWord'
classes/json.lua:301: in function
(tail call): ?
classes/json.lua:457: in function
(tail call): ?
classes/json.lua:415: in function
(tail call): ?
(tail call): ?
(tail call): ?

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Hello, firstly you need to have correct json format

    not
    [{"type":"backgrounds","back":back1.png}]
    but
    [{"type":"backgrounds","back":"back1.png"}]
    and not
    [{"type":"backgrounds","back":tile.png}]
    but
    [{"type":"backgrounds","back":"tile.png"}]
    and about using background value, you need to do something like:
    local background = Bitmap.new(Texture.new("graphics/"..value.back, true))
  • Wow thank you so much it works :)
Sign In or Register to comment.