valerypopoff's Recent Forum Activity

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

  • [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:

  • Thanks for your answer.

    It would be really handy if the expression JS.AliasValue(alias) returns a json string if the value is an object or an array.

    Imagine AliasValue returns a json string of a js-object. How would you use this string in Construct?

  • Thank you!

    1-would it be possible to add trigger support ?

    I didn't add trigger support because:

    — You can come up with your own triggers (boolean variables) and use Compare

    — If you're operating with Promises in your js functions, triggers won't help you. Like: ok, the function is executed, here we are, shooting the trigger, but what the function really does is not finished yet. So you will have to manually do some «this.ShootMe()» in your js code when the Promise resolved. Sounds like API to me. I want any js code just work without it knowing that it's being executed in some special environment.

    — I believe, this is a broken architecture if you want to make Construct do something right after asynchronous js-algorithm is finished. If you need something to be done right after something else, do it in javascript. Don't bother Construct with that. If you really need Construct to react on a result of your js-algorithm, use states. This is a more consistent way of doing that. Pseudocode:

    js:
    Promise resolved ? Player.state = "walking".
    
    construct:
    Compare alias [Player.state] == "walking" ? player_sprite.SetAnimation("walking_anim")
    [/code:5yui0vlz]
    What do you think of it? Don't hesitate to share your ideas and tell me more about your architecture. 
    
    
    

    2-In your landing page you said that "Javascript Plugin is slower than built-in Construct instructions and functions"

    Do you mean that a chunk of code written in JS is slower that code written with construct's ACEs ?

    No. A chunk of code written in JS is always faster that code written with construct's ACEs. Because pure js is always faster.

    What I meant is that the whole process of calling the action "Call JS function" that executes js function "Foo" that does "i=0" is slower than Construct instruction "Set variable i to 0". The js code itself is faster. What is slower is calling a plugin action. The more your JS does (not just "i=0"), the smaller the difference. Iterating through large arrays are much faster in js than in Construct, for example.

    3-Does your plugin uses any ecmascript 6 features that might not be supported in older browsers or mobile ?

    Thanks.

    Oh! Good question, thanks! I forgot to mention it in a FAQ. No, it doesn't use any ecmascript 6 features.

  • I think i kinda see what you're trying to do. You can do this, yes:

    EDIT: I think I found a way to do this... ignore this post for now

    function Compare(a,attacker,target) {
    	var stat = {armor:0, crit:1, critDmg:2, dmg:3, mhp:4, hp:5, shotcount:6};
    	
    	var aArmor = attacker.split(",")[stat.armor];
    	var aCrit = attacker.split(",")[stat.crit];
    	var aCritDmg = attacker.split(",")[stat.critDmg];
    	var aDmg = attacker.split(",")[stat.dmg];
    	var aMHp = attacker.split(",")[stat.mhp];
    	var aHp = attacker.split(",")[stat.hp];
    	var aShotCount = attacker.split(",")[stat.shotcount];
    	
    	var tArmor = target.split(",")[stat.armor];
    	var tCrit = target.split(",")[stat.crit];
    	var tCritDmg = target.split(",")[stat.critDmg];
    	var tDmg = target.split(",")[stat.dmg];
    	var tMHp = target.split(",")[stat.mhp];
    	var tHp = target.split(",")[stat.hp];
    	var tShotCount = target.split(",")[stat.shotcount];
    
    	return eval(a);
    }[/code:10uk0rlf]
    
    

    It's just you wouldn't have to do that if you had Player and Enemy objects in javascript from the very beginning. The plugin allows you to keep the whole model part in javascript and never store object data in Construct. So you never have to pass data to javascript. You just call certain javascript functions with certain parameters.

    Imagine that you only have player's and multiple enemie's sprites in Construct. And these sprites only represent the objects. They are not the objects. They don't store any data except their own x and y sprite coordinates. These sprites have only to have one instance variable — id. This is how you know that this certain sprite represents this certain object in javascript.

    Also imagine that you have "Player_sprite on collision with Enemy_sprite condition". And you do "Call JS function" with parameters:

    Name: CalculateDamage

    Param 0: Player_sprite.id

    Param 1: Enemy_sprite.id

    And also imagine that you have something like this in javascript:

    var players = [];
    
    var Player = 
    {
    	armor: 100, 
    	crit: 50, 
    	critDmg: 20, 
    	dmg: 10, 
    	mhp: 10, 
    	hp: 75, 
    	shotcount: 0
    }
    
    var Enemy = 
    {
    	armor: 100, 
    	crit: 50, 
    	critDmg: 20, 
    	dmg: 10, 
    	mhp: 10, 
    	hp: 75, 
    	shotcount: 0
    }
    
    function InitGame()
    {
    	players.push( Player );
    
    	return players.length-1;
    }
    
    function CreateEnemy()
    {
    	players.push( Object.assign({}, Enemy) );	
    
    	return players.length-1;
    }
    
    function CalculateDamage( attacker_id, attacked_id )
    {
    	var attacker = players[attacker_id];
    	var attacked = players[attacked_id];
    
    	attacked.health -= attacker.damage;
    	...
    }
    [/code:10uk0rlf]
    
    This is how you're really supposed to use the plugin.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Did I get this right? You have a global Construct variable called ShotCount. You have a js function called Compare (Sic!) that takes a string argument, evals it and returns the result. Then you call js function "Compare" from Construct with the action "Call js function" and pass the parameter which is basically "shotCount % 3 == 0".

    If I got this right, you get a fair response "shotCount is not defined". Because there's no such variable in global scope of your js-script. Construct variables are not real. They don't exist in your js-script. Construct variables are virtual and only make sense to the engine itself and to the js-plugin ACEs. So if you want your js script to operate with construct variables (which is totally upside-down), you should either pass them as arguments to js functions, or create js variables in your script, set their values to Construct variables values (use aliases) and then operate with those js variables.

    If you're just playing around with the plugin, it's alright. But if you're really trying to achieve something here, this something is not clear to me. Maybe if you tell me what you're trying to do, we'll find a suitable solution for that.

    Also can you send me a project file please?

    Amazing plugin! I ran into a little problem I was hoping you could help me with:

    I'm trying to use this script to eval a string. This string could contain any number of global variables and even call functions

    A test string, called var1 is this: "shotCount % 3 == 0"

    The event is JS Call Function "Compare" with parameter 0 being var1

    The .js file has this:

    function Compare(a) {
    	return eval(a);
    }[/code:2t75r8km]
    
    But it doesn't work, it says "shotCount is not defined" in the log. If I change var1 to something like "2+2" it evals correctly.
    I don't want to pass the global variable because I need this to be flexible and allow multiples and any variable. Do I need to somehow put the variables into the scope of the JS plugin?
    
  • The new version of a plugin is out! Check it on plugin's promo page:

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

    What's new:

    — Aliases: an easy mechanism to work with js-objects, its properties and methods

    — Plugin is now "Single global" which means you can only have one instance of a plugin in a project

    — Everything works faster because functions and aliases aren't implemented with eval( ) anymore

  • CS2 Plugin version is down dude.

    Freaking dropbox! Fixed it, thanks

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