[help] - Dynamic Text via Javascript

0 favourites
  • 7 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • 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.


    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]
  • On some_event set some_var

    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'
    In terms of construct, still confused how I [set text] "artist_name" in the example above.
  • You're missing a '}'

      return{ 'prop' : 'some_value'};
    One other thing, don't forget to change your variable to 'text'
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

    	function myFunction(){
      return{ 'prop' : 'some_value_works'};
    This can also be simplified.
    [code:daw4yl7s]    	<script>
    artist_name = "VALUE_2"
  • -- 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


    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)