JSON Loading questions

Not sure what I’m doing wrong…

Just trying to get a simple JSON file test to load…

relevant screens:

Nevermind just figured it out - removed [resource] item and it started working - but this does go to a point I filed on the docs page about confusion between how the game project file editing works now vs. what’s in docs.

Actually, now even weirder. I changed nothing in the script and now I’m getting the error again…

Do you edit the game.project file from within the editor in text mode? Do you have it open in more than one tab? Can you try a full Project->Rebuild and Launch?

So in the end it doesn’t seem to be the problem now. The problem now - which I need to recreate is that I guess what happens is any following code on the table object referencing the Json triggers a similar error such as:

WARNING:SCRIPT: Failed to load resource: /main/Layouts/region-layout1.json (-3)
ERROR:SCRIPT: main/text-display.script:15: bad argument #1 to ‘decode’ (string expected, got nil)
stack traceback:
[C]: in function 'decode’
main/text-display.script:15: in function <main/text-display.script:1>

Which as written seems like it’s not loading the resource, but in fact it is, but then downstream errors occur and it display that error…

I guess the summary, so far, is that unless certain JSON decoding code is clean all the way through it can throw an error that seems related to the original acquisition of the file vs. parsing it…

Ok, so if you print() the data you get back from sys.load_resource() it’s actually not nil? If this is correct could you please share the json here?

The data is fine. The code is fine. When I break downstream code e.g.:

this is good code:

local data = sys.load_resource("/main/Layouts/region-layout1.json")
– Decode json string to a Lua table
local layout_table = json.decode(data)
pprint(layout_table)
pprint(layout_table.Region1.x_size)

but if I take the last line and do something like

pprint(layout_table.ReGion1.x_size)

The error it makes includes:

WARNING:SCRIPT: Failed to load resource: /main/Layouts/region-layout1.json (-3)

which of course makes me think the resource still isn’t loading properly when I do the call:

local data = sys.load_resource("/main/Layouts/region-layout1.json")

Ideally shouldn’t WARNING: be more specific to the mistake in parsing.

It’s nitpicking but just making the point that the core top-line bug message made me think I still had some sort of file routing error in the project file or something else. This was made worse by the fact, that originally, that is the problem I had.

  • Ben

I’m not able to reproduce this issue. Can you perhaps isolate it down to a minimal example and share it with me?

I’ll try to do that tomorrow morning…