Is it possible to have a dependency to a external file (http

  • In my javascript SDK I want this because I need to include a script source with a unique key, like:

    "http://www.mapquestapi.com/sdk/leaflet/v1.s/mq-map.js?key=UNIQUEKEYHERE"

  • FYI, my current workaround is as follows:

    I just change the generated index.html to include

    <script src="http://open.mapquestapi.com/sdk/leaflet/v1.s/mq-map.js?key=UNIQUEKEY></script>

    However I (officially) have to do that every time I generate executable code and I lose the advantage of running the capx from within construct 2

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Dependency are defined in the edittime.js file. As per the manual :

    dependency

    This one isn't listed above, but if you need external files bundled with your plugin (e.g. a javascript library) you can specify one or more dependency files with:

    "dependency": "file1.js;file2.js;file3.html"[/code:wxse6q3n]
    
    
  • Thank you.

    However that does not work with files that are not stored in the plugin folder AFAIK, such as in OP.

  • hey , in your plugin runtime.js , in the function "onCreate"

    add this

    $.getScript( "YOUR SCRIPT URL", function( data, textStatus, jqxhr )

    {

    // when the script is loaded here you can use it

    });

    Have fun making plugins

  • Thank you.

  • you are welcome

  • hey , in your plugin runtime.js , in the function "onCreate"

    add this

    $.getScript( "YOUR SCRIPT URL", function( data, textStatus, jqxhr )

    {

    // when the script is loaded here you can use it

    });

    Have fun making plugins

    Thats not a good idea. I have tried this in x versions.

    Thats a async load, it much times comes to late!

    You can try it with sync load, but best to be sure its loaded correctly, is to have it in your addons and load it in edittime!

    jQuery.ajax({
        async:false,
        type:'GET',
        url:script,
        data:null,
        success:callback,
        dataType:'script',
        error: function(xhr, textStatus, errorThrown) {
            // Look at the `textStatus` and/or `errorThrown` properties.
        }
    });[/code:32lxcnd3]
  • deathangel1479 , onCreate is loaded before the game started , and the script size is at max 50Ko , it's not that hard loading ,

    @stefan52a you can use this the sync loading with ajax

    $.ajax({

    url: "SCRIPT_URL",

    dataType: "script",

    async: false,

    success:function()

    {

    // when the script is loaded here you can use it

    }

    });

    or here is a better one , add it inside the onCreate

    $("head").append('<script src="http://open.mapquestapi.com/sdk/leaflet/v1.s/mq-map.js?key=UNIQUEKEY></script>');

  • If construct project is in cache, its real fast +- some ms between "onCreate" and "onLayoutStart", and I only say that it can be, in especially if you have a fast system and slow internet. I would not count on it, to much unknown!

    I had much errors with unloaded stuff, but was also a big script... 128KB

    Yes, sync is much better.

    I think .append() is also async, not?

  • .append() will add the <script src="http://open.mapquestapi.com/sdk/leaflet/v1.s/mq-map.js?key=UNIQUEKEY></script> to the "index.html" file

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