[Plugin] JavaScript (C2 and C3)

2 favourites
From the Asset Store
A cool way for kids to write and practice English Alphabets
  • valerypopoff privet! A very useful plugin, but in C3 "All Scripts Loaded" is executing continuously every frame, instead of only once, when everything is loaded.

    Also trying to understand how to use another js library like https://tonejs.github.io/

    • I include both scripts Tone.js and Main.js into C3
    • Than I am trying to call something from Tone.js in the Main.js, but it seems like I am missing some kind of reference to Tone.js, it throws "Tone is not defined"
    • Although, I can call Tone.js methods directly from JS-plugin with "Execute Code"

    OK, found out why it's happening, you should put everything related to another library inside a function and call it from C3, otherwise it will call it too early, before library was completely loaded, strange that it's happening even after "All Scripts Loaded"

    This plugin makes a lot of sense - insane possibilities with libraries, SDK's and API's in a very elegant highlevel architecture of construct <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • in C3 "All Scripts Loaded" is executing continuously every frame, instead of only once, when everything is loaded.

    Of course it is. It's a condition, not a trigger. If you want something to be executed just once when all scripts are loaded, use System condition «Trigger once».

    Also trying to understand how to use another js library like https://tonejs.github.io/

    - I include both scripts Tone.js and Main.js into C3

    - Than I am trying to call something from Tone.js in the Main.js, but it seems like I am missing some kind of reference to Tone.js, it throws "Tone is not defined"

    - Although, I can call Tone.js methods directly from JS-plugin with "Execute Code"

    OK, found out why it's happening, you should put everything related to another library inside a function and call it from C3, otherwise it will call it too early, before library was completely loaded, strange that it's happening even after "All Scripts Loaded"

    Are you still experiencing some problems with that or not? I don't get it.

    This plugin makes a lot of sense - insane possibilities with libraries, SDK's and API's in a very elegant highlevel architecture of construct <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Thanks!

  • valerypopoff So far no problems, thanks What do you think about "Behavior" version of this plugin? So that it is possible to use it on an object instance level, like for example a tweening library on a Sprite object? Does it make sense?

  • What do you think about "Behavior" version of this plugin? So that it is possible to use it on an object instance level, like for example a tweening library on a Sprite object? Does it make sense?

    Not sure I get what you mean. How can it be any different on an object instance level? I mean, imagine there's a js-function. What difference does it make if you call it on an "object instance level"?

    And what is "tweening library on a Sprite object"?

  • For example using this tweening library to animate properties of the object: https://github.com/byrdal/tween-js sure, this can be achieved by just using a plugin, but I think it can be more straight forward as a behavior.

    Are you planning to add a callback functionality into your plugin? Sort of an async trigger.

  • For example using this tweening library to animate properties of the object: https://github.com/byrdal/tween-js sure, this can be achieved by just using a plugin, but I think it can be more straight forward as a behavior.

    Now I get it, thanks. Well, I thought of implementing it as a behaviour. When I gave it a thought, I realized that a plugin would be much more multipurpose. I'm pretty sure you can see this.

    Are you planning to add a callback functionality into your plugin? Sort of an async trigger.

    I thought of that too. But I decided that the system of states (that you can implement yourself) is no worse. And furthermore, if I implemented a system of Construct-triggers, you would have to fire them in your js-scripts with "runtime.trigger()". Sounds like API to me. I didn't want not to burden user scripts with that.

    Callbacks make a lot of sense in a system where a programmer doesn't do event management — like javascript invoronment. In Construct you have framerate-based event sheets. So just check the state of a js-object every frame and do something if the object's state is legit.

    I stand by MVC paradigm. A game object shouldn't shoot a trigger that moves the sprite. A game object knows nothing about sprites, Construct does. Construct should move sprites according to the game object's properties. In other words, a game object shouldn't draw itself. If you want to shoot a Construct trigger that does something that you can't see (changes states, checks the logic...), then don't. Construct doesn't have to do that. Do that right in JS. Construct should only draw things, get user's input and pass it to JS.

    In other words, again, if you're using a tweening library, tween the variables in your JS, not the sprites. On second thought, tweening on a js-side doesn't make any sense because it's supposed to be framerate-related.

  • Thanks for the explanation. What is the best way to use a tweening library?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Javascript has it's own real time. Construct has it's own virtual relative time that can even be paused or even slowed down. You can use the tweening library alright but there’s nuances to it.

    Imagine you're doing some movement tweening in Javascript using this library. And in the middle of the tweening your slow down the Construct virtual time. Everything in the game slows down. The movement that should have been finished in 2 seconds, should be finished in 4 seconds now. So you also need to slow down the tweening library's virtual time too (if it's possible in the library).

    Thanks for the explanation. What is the best way to use a tweening library?

  • Ah, I see, will experiment with the time aspect.

  • Is a port from the plugin to the new C3-Runtime possible ? :)

  • As soon as C3-Runtime is released. As long as I understand, it's still in alpha.

    Is a port from the plugin to the new C3-Runtime possible ? :)

  • Is there any access to the runtime - canvas div with your plugin and with a own javascript-call? valerypopoff

    	function test() {
    		console.log(typeof cr.runtime.canvasdiv); // get undefined
    	}
    
  • There's access to the runtime from global javascript scope. You can access it using my plugin or just using Construct Browser plugin.

    How to access canvas div via cr object — has nothing to do with the way you invoke javascript. Can't help you with that, sorry.

    Is there any access to the runtime - canvas div with your plugin and with a own javascript-call? valerypopoff

    > 	function test() {
    		console.log(typeof cr.runtime.canvasdiv); // get undefined
    	}
    
  • thanks for this plugin!

  • Hi, i've a problem with arrays. I've two functions in my js, the first one return an array as result, and it works correctly. Then i need to call the second one passing the array (stored in an alias) as parameter but it seems to not working. What i'm wrong!?

    As you can see, "wavePoints" is an array, and i would like to pass to "updateWavePoints" function.

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