valerypopoff's Recent Forum Activity

  • Maybe this will help construct.net/make-games/addons/1/javascript

    Call JS (cjs) Joe7, PLEASE.

  • 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 ? :)

  • This is because you do this.runtime.getProjectFileUrl(nameScript) in the global scope. This is supposed to be executed from inside of the plugin/behavior instance. When you do this in the global scope, your "this" is a window object that has no "runtime" property.

    From the global scope try c3runtime.getProjectFileUrl

    Ashley With C3 Runtime I have this error:

    Error executing JavaScript: TypeError: Cannot read property 'getProjectFileUrl' of undefined

    This is my code:

    > var nameScript= 'mathjs.js';
    var realUrl = this.runtime.getProjectFileUrl(nameScript);
    var jsFile = document.createElement('script');
    jsFile.src = realUrl;
    document.head.appendChild(jsFile);
    

  • 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?

  • 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.

  • Try Construct 3

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

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

  • 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!

  • Cheers!

    Aliases are string shortcuts for js-variables, arrays, objects and functions. You can't initialize an alias with the object declared with const or let. Only var. And I just realized I never said that explicitly in the documentation. My bad.

    If you're interested why it works like this, here's an explanation. If you initialize the alias "Alias" with the js-string "jsobj", later when you do JS.AliasValue("Alias"), it actually returns the value of javascript:

    window["jsobj"][/code:g9xwxm4j]
    Global js-variables declared with [b]var[/b] become the properties of the [b]window[/b] object. Global objects declared with [b]const[/b] or [b]let[/b] – don't.
    
    But you can get the value of a global variable declared with [b]const[/b] or [b]let[/b] using the expression [b]JSCodeValue[/b] like this: JSCodeValue("testCONST"). It works because it is translated to javascript:
    [code:g9xwxm4j]eval("testCONST")[/code:g9xwxm4j]
    
    
    

    First: Thanks for this useful plugin It's awesome!

    I have a problem with AliasValue: it's ok with var, not with const and let.

    But if I pass const and let to a function, and I use Call function, I can get the correct value.

    What's wrong?

  • Thanks!

    Let's assume that you have this kinda thing in your Javascript file:

    var PlayersArray = [];
    
    PlayersArray[0] = 
    {
     name: "Player Zero",
     score: 666
    }
    ...
    [/code:1j8tuzvw]
    Then in Construct you create sprites and assign their Y coordinate according to the player's score. Assume your Javascript Plugin object is called JS. Player sprite object is called PlayerSprite. I'd do this:
    
    Condition: JS->AllScriptsLoaded
    Action: JS->InitAlias "PA" with Javascript "PlayersArray"
    
    Condition: System->For loop
    From: 0
    To: JS.AliasValue("PA.length")
    Action: System->CreateObject of type PlayerSprite
    Action: PlayerSprite->SetY to JS.AliasValue("PA["& loopindex &"].score")
    
    
    > Hello @valerypopoff,
    > let me thank you for this great software first of all, it could be that extra programming gear Construct was missing.
    > 
    > Then, a request for advice  
    > Let's assume i've got an array of js objects representing players in a board, and that I have to do some stuff with this data, so to handle it, I use a js file and connect it to C2 with your plugin. If I want to create a 'player' sprite on the board for each object in the array, is there a way to import the array in C2 and iterate over it? How would you suggest to do that? To split the problem into multiple get function calls?
    > 
    
  • Does this plugin have support for Construct 3?

    This one does:

    https://readymag.com/valerypopoff/valer ... js-plugin/

  • Updated to v.0.6.2:

    — Added "Compare alias call" condition

    — Placed all eval ACEs into separate section

  • This is what I want to do in C2 :

    You're almost good to go. You should do this:

    var ScoresArr = ["111","222","333"];
    
    function GetScoresCount()
    {
    	return ScoresArr.length;
    }
    
    function GetScore( id )
    {
    	return ScoresArr[id];
    }
    [/code:2xarrmhj]
    
    [img="http://valerypopoff.ru/temp/scirra-forum/aekiro.png"]
    
    Look at the picture and note where you're mistaken, it's important. For example, you got
    [code:2xarrmhj]
    JS.AliasValue("myarray." & loopindex)
    [/code:2xarrmhj]
    That makes no sense because you don't access array items via dot like this "myarray.0". You do this via brackets like this "myarray[0]". And this has nothing to do with the plugin. It's javascript basics.
    
    
    

    But you said that looping over an array defined in js script in C2 is a bad idea (cf my previous questions).

    If it's a bad how can I get my scores to build a leaderboard ?

    I think I jumped the gun with that statement. What I was rtying to say is that this is generally a bad idea if there's a better way of doing this. In this particular case there's no other way. There's an array in JS, and there are spites in Construct. If you want to translate JS-model into visible sprites, you have to "parse" the model. In our case you have to iterate through js-array from Construct and create sprites respectively.

valerypopoff's avatar

valerypopoff

Early Adopter

Member since 7 Aug, 2016

Twitter
valerypopoff has 34 followers

Connect with valerypopoff

Trophy Case

  • 8-Year Club
  • RTFM Read the fabulous manual
  • Email Verified

Progress

10/44
How to earn trophies