valerypopoff's Forum Posts

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

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

  • I still don't understand what you mean by "how". Is it the javascript itself that you're struggling with? Or is it JS Plugin? What is it exactly you don't know how to do?

    Anyways, the process would be absolutely the same:

    The array of scores is in a JS array:

    var ScoresArr = [222, 235, 547, 12346, 325];
    [/code:nztqujon]
    You go to Construct and loop the JS array like this: for each item in the array
     — create a sprite ( a line of the leaderboard )
     — create a text and set its value to the current score.
    
    So, what is it exactly that's not clear here? I can't help you if you don't ask a certain question. Or at least i need to understand what you're struggling with. You don't know javascript? You don't know Construct? Or is it just the plugin? 
    
    I don't want to torture you to death by the way   . I want to help you. I swear I will freaking do this for you and send you the C2 file that does what you need if I see that I can't help you otherwise. It's just... I still hope that I can.
    
    
    

    Sorry, maybe I wasn't clear.

    The array of scores would be in a C2 array.

    I would loop the C2 array like this :

    for each item in the array

    - create a sprite ( a line of the leaderboard )

    - create a text and set its value to the current score.

    So, how would I do this if my array is in js-script ?

  • Ok, then how do I build a leaderboard (the view) in C2 based on an array in my js script ?

    I can help if I understand what do you mean "how". How would you do this if the array wasn't in js-script?

  • The function still isn't working (normal also does not appear to be defined) but now at least I can investigate what's going on there in the js file . Thanks again!

    Well it worked, i checked. Can you share the project file again? I'll look into it.

  • 1-Do you think looping over an array (defined in js script) in construct (to build a leaderboard for example) is a bad idea, since everytime the JavaScript plugin need to parse an alias expression ?

    This is a bad idea and wrong on so many levels. The whole point of the plugin is that you don't have to loop over arrays in Construct anymore. Construct is designed neither for modeling data, nor for programming algorithms with loops, arrays and stuff. But you can still do that if you want to. It's just a little bit slower.

    2-It would be nice if we can get the return value of a function with an expression, currently I have to call the alias and use the StoredReturnValue expression, it would be nice if we can do this in one step.

    Word. Gonna do that soon.

    3-difference between "call alias" and "call function" ? the preferred one of the 2 ?

    There's no preferred one. It all depends on what you have in your code. If there's just a global js-function, it's easier to do "Call JS function". If there's a js-object that has multiple properties and methods you would want to access later from Construct, it's easier to come up with the alias for this object and do "SetAlias", "Get Alias" and "CallAlias".

    Cheers.

  • If you look in the browser console (always look in the console, you're working with javascript for Christ's sake), you'll see error message:

    JS code: jstat.normal.cdf
    jstat is not defined
    [/code:iy76sa4y]
    
    And this is true. Thre's no "jstat" variable or object in your js script. No wonder, the result is "undefined" which is interpreted by Constrauct as zero. 
    
    But there's "jStat". So what you wanted to do is call "jStat.normal.cdf" function, right? You should use "Call JS function" action then. Like this:
    
    [img="http://valerypopoff.ru/temp/scirra-forum/jstat.png"]
    
    Don't use "Execute JS code" action unless it's absolutely necessary, because it uses "eval", which is slow.
    
    
    

    Hey valerypopoff, I'm excited to use your plugin but I'm having trouble integrating a few files into a project that I've got working in the command line otherwise. What I'm essentially trying to do is call a function from the jstat library to convert a z score to a percentage value. In my most recent attempt I'm only using jstat and trying as many combinations of things as I can think of bit my return value is always 0.

    This is a small project I'm tinkering in to try and get a percentage value:

    https://www.dropbox.com/s/qwy5nyslwp157 ... .capx?dl=0

    I don't share the file to have anything done *for* me, just to get info on how to get things moving. I'm not sure what I could be doing wrong here. Any help learning to effectively use this plugin is appreciated!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [quote:babvkc1m]Imagine AliasValue returns a json string of a js-object. How would you use this string in Construct?

    Another plugin would, that expect a json value.

    That is very interesting. I'm just trying to figure out what is it you're trying to do here. So you have the object in js. Then you get it's JSON string in Construct. Then you pass this JSON string to a plugin that reads JSON. And then what? Access object's properties?

    If so, and you just need to access js object's properties, just do this: