OttoRobba Posted January 30, 2015 Share Posted January 30, 2015 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 loadergame.addAsset('crops.json');But the following returns undefinedgame.cropsData = game.getJSON('crops.json');console.log(game.cropsData);Any clues? Using latest PandaJS Quote Link to comment Share on other sites More sharing options...
enpu Posted January 31, 2015 Share Posted January 31, 2015 Hmm that works ok with me. Do you have your json file in media folder? Quote Link to comment Share on other sites More sharing options...
OttoRobba Posted January 31, 2015 Author Share Posted January 31, 2015 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:console.log(game.json["media/crops.json"]);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. Quote Link to comment Share on other sites More sharing options...
enpu Posted January 31, 2015 Share Posted January 31, 2015 I used your json data. Can you show your full code? Quote Link to comment Share on other sites More sharing options...
OttoRobba Posted January 31, 2015 Author Share Posted January 31, 2015 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. Quote Link to comment Share on other sites More sharing options...
enpu Posted February 1, 2015 Share Posted February 1, 2015 You are trying to get the JSON data before it's loaded. OttoRobba 1 Quote Link to comment Share on other sites More sharing options...
OttoRobba Posted February 1, 2015 Author Share Posted February 1, 2015 Ahhh ok, got it. When called inside the scene init it works properly. Thank you so much Enpu, I was pulling my hair already haha Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.