Browser.ExecJS javascript function return JSON for Array

0 favourites
  • 2 posts
From the Asset Store
Platform HTML5 game, where the little Dinosaur must cross the forest, desert and snow forest.
  • Trying to run a Javascript function I have added into the body of the index.html to return a JSON string I can add into an Array inside of Construct2.

    [attachment=0:3l5z7udg][/attachment:3l5z7udg]

    Here is the javascript I add in the body of index.html:

    <script type="text/javascript">
    		function gameJSON()
    		{
    			var myGameJSON =  <cfoutput>#myJsonVar#</cfoutput>;
    			return myGameJSON;
    		}
    	</script>
    [/code:3l5z7udg]
    
    This code functions in the browser console and returns a correct JSON to the browser console. I also know it gets called in construct2 because I have added an alert and I have am seeing the alert.
    
    I have looked at the input from Browser.ExecJS("gameJSON();") by appending it to a text string and the value is just = "0".
    
    Questions:
    1. Can I use Browser.ExecJS to request a JSON string and then use that to load to my "ArrayInfo"?
    2. Is there a better method to reference a Javascript function on index.html accessed via the Browser object and get the JSON inside construct2?
    
    Any help is greatly appreciated.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1. ExecJS can only return strings or numbers, so make sure the JSON is stringified and not a raw JS object.

    2. I would strongly recommend always using the Javascript SDK instead of executing JS strings directly.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)