[help] - Dynamic Text via Javascript

0 favourites
  • 7 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • Hey Everyone,

    I am working with our developer who will be helping me do some back end development to load in dynamic content. He will be providing me some JavaScript that will load (3) dynamic variables. However, I have never messed with dynamic JS in construct and I am not sure how to post that data.

    QUESTION:

    1. How would I inject the (3) JS objects "artist,bio,trait" into Construct as text.

    2. Do I need to make a custom plugin for this?

    Quick "fake" JS snippet

    //this function goes into construct
    function MusicToConstruct(data) {
    
      //here's a fake data object. Anytime the MusicToConstruct function is called by my code, it will contain this data object. So remove this when we get the real one working
      var data = {
        artist: 'Alestorm',
        bio: 'blah blah blah i\'m a long string',
        trait: 'pirate metal'
      }
      //end fake data object
    
    }// JavaScript Document[/code:3ufvqt71]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On some_event set some_var

    Browser.ExecJS("window['obj_name']['prop']")[/code:1v0d8p4t]
    Where you've defined [code:1v0d8p4t]obj_name = {'prop':'Some text'}[/code:1v0d8p4t] globally;
    
    Then if you need to fetch some_var from your script;
    you can look for them in c2canvas.c2runtime.all_global_vars 
    [code:1v0d8p4t][{'name':'VariableName','data':'Value' .... }, { ... }];[/code:1v0d8p4t]
  • Thanks Noncentz705 really appreciate the help.

    Please forgive me if I may not be comprehending all this properly. "I am not an advanced developer"

    I am still a bit confused how I set this up.

    * this is the code I will add to my index.html

    function myFunction(data) {
      var data = {
        artist_name: 'Alestorm'
    }[/code:1ec5rp9w]
    
    In terms of construct, still confused how I [set text] "artist_name" in the example above.
    [attachment=0:1ec5rp9w][/attachment:1ec5rp9w]
  • You're missing a '}'

    myFunction(){
      return{ 'prop' : 'some_value'};
    }
    [/code:2g36nqw8]
    [code:2g36nqw8]Browser.ExecJS("window['myFunction']()['prop']")[/code:2g36nqw8]
    
    One other thing, don't forget to change your variable to 'text'
  • Oh nice catch! Thank you very much for the help. Tested and it works

    For others that need this in the future.

    CAPX -[attachment=0:daw4yl7s][/attachment:daw4yl7s]

    JavaScript added to index.html

         <script>
    	function myFunction(){
      return{ 'prop' : 'some_value_works'};
    }
    </script>[/code:daw4yl7s]
    
    This can also be simplified.
    
    [code:daw4yl7s]    	<script>
    artist_name = "VALUE_2"
    </script>[/code:daw4yl7s]
    
    [code:daw4yl7s]Browser.ExecJS("artist_name")[/code:daw4yl7s]
  • -- REMOVED --

  • my callback is not working , gives an error in CocoonJS 'undefined is not an object (evaluating 'runtime.types.Function.instances')

    Here is capx , https://dl.dropboxusercontent.com/u/800 ... lback.capx and modified index.html

    https://dl.dropboxusercontent.com/u/80050021/index.html

    Please help , I am also trying this method, solved-how-do-i-callback-in-outside-of-canvas_t109372 gives a different error ,

    ' undefined is not a object (evaluating 'IN['cr'].plugins_')

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