Jump to content

getJSON returns undefined


Recommended Posts

Hey there folks.


I've been trying to get this json to work with PandaJS but no success so far.

{  "raddish": {    "type": "raddish",    "value": 1,    "time": 3,    "rot": 6,    "seeds": 3  }}

I have added it to the loader


But the following returns undefined

game.cropsData = game.getJSON('crops.json');console.log(game.cropsData);

Any clues?


Using latest PandaJS

Link to comment
Share on other sites

It is in the media folder and I can access the json data with the console in the browser, so I know it is properly loaded. For instance, if I do this in the console:


It properly prints the object in the json. If I try the same directly from my game files, it errors out with undefined.

Tried a fresh install from Pandatool, still getting undefined.


Do you have a sample with a working json? I could see if that errors out and further test it.

Link to comment
Share on other sites

I compacted it as a zip, in case there is something up with the files. (http://www.filedropper.com/testjson)


But it is a basic project, made with Panda install.

game.module(    'game.assets').body(function() {  game.addAsset('crops.json');});
game.module(    'game.main').require(    'game.assets',    'game.objects').body(function() {game.cropData = game.getJSON('crops.json');game.createScene('Main', {    init: function() {      console.log(game.cropData);    }});});

And this is the json, named crops.json and stored within the media folder:

{  "raddish": {    "type": "raddish",    "value": 1,    "time": 3,    "rot": 6,    "seeds": 3  }}

If my files work for you then it ought to be something between Panda and Linux.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...