valerypopoff's Forum Posts

  • valerypopoff - any thoughts on the future of this plugin and the vardic issue in C3? The plugin is so useful (thank you), but we hear chatter about vardic support being removed in C3, etc.

    [SDK] Addon 'ValerypopoffJSPlugin' ACE 'compare-exec-return-with-parameters' uses "variadic" parameter which is not supported in the SDK. Only use supported parameter types in your addons. Please refer to the SDK documentation for supported types.

    Hey! Well, I saw it coming. We discussed the issue with Ashley once and he made it clear that they're gonna outlaw the use of variadic params in conditions and maybe even in actions. When it finally happens, this is a problem to all my plugins, not only for Javascript Plugin.

    If they only kill variadic parameters in conditions, I'll remove the "Compare value" condition and instead of a direct comparison with a condition you'll have to get the value with the expression first (System->Set value TEMP to JS.Value(...)) and then compare it (System->Compare two values).

    If they kill variadic params in actions as well, then instead of just calling an action

    JS.CallFunction with params (1,2,3,4,5)
    

    you'll have to do

    JS.FlushParams
    JS.AddParameter (1)
    JS.AddParameter (2)
    JS.AddParameter (3)
    JS.AddParameter (4)
    JS.AddParameter (5)
    JS.CallFunction
    
  • I guessed it. Yeah...i take it as it is, and i am thankfull. Cheers. But i will ask you again some questions ;-)

    Any questions about the plugin, sure!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Spax

    Okaaaaay. I can't (or want to) help you with learning JavaScript or Construct SDK anymore than I already did, so I'll go with "thanks, cheers".

  • Hey, this is a really great plugin !

    Thanks!

    1.) Can i command directly a "Sprite" inside C2, named "sprite_test" , by my outside "test.js"-file ? If yes, what is the command for it ? I didn´t found any info about it.

    Since every sprite or any other game object exists in the runtime (which is a javascript object), you can access it from js script. I have no idea how to do that and I wouldn't recommend it. You're not supposed to do that, so you'll probably break it if you try to do that. But. You can totally call Construct Functions from js and it's totally legit:

    function CallConstructFunc(func_name, args_array)
    {
    	args_array = (args_array === undefined) ? [] : args_array;
    	
    	if( typeof c2_callFunction != "undefined" )
    	{
    		return c2_callFunction(func_name, args_array);
    	}
    
    	if( typeof c3_callFunction != "undefined" )
    	{
    		return c3_callFunction(func_name, args_array);
    	}
    }
    

    2.) Does an external *.js have an impact to the whole performance of the game ?? I was just thinking about the communication of variables from extern JS to C2 and vise versa, that it could slow down the information flow.

    As stated in the JS Plugin documentation, plugin's ACEs are a little bit slower than native Construct Event Sheets instructions. A little bit. This is all due to the ACEs calls that take time. The js code itself is executed as fast as it can be on your device. The JS Plugin already uses caching that saves a lot of time on ACEs calls.

    And last but not least: it wasn´t easy to get info about API / commands for the extern JS / and intern C2 commands. All i found was in this thread here. Therefore i would recommend to the devs, to make a kind of API link onto their website (with a search function & examples)

    What API? There's a documentation here: valerypopoff.ru/construct/js-plugin What else do you want it to cover?

  • From what I understand, it's easy to access the runtime object from the global scope with:

    — window["c3runtime"] in C2.5

    — window["c3_runtimeInterface"]._GetLocalRuntime() in C3

    And if I get it right, it's only made so the engine itself could call functions like

    — window["cr_getSnapshot"]

    — window["cr_sizeCanvas"]

    — window["cr_setSuspended"]

    from within global functions and event listeners where the runtime object can't be accessed otherwise.

    I have a problem with it because when the runtime object is exposed to the global scope, it's impossible to impede shenanigans with the game data (from the javascript console, for example).

    Are you planning on doing something with it?

    Ashley

  • Toddler Thanks!

  • valerypopoff, do you think there is a way to say for example, create a class on the *.js side and then make every instance of a sprite have an instance of that class ?

    Think of it as polymorphism, your "extends" so to speak.

    I don't think that you actually meant polymorphism. Polymorphism means something else.

    I don't know what you mean by "make instance of a sprite HAVE an instance of js class". You certainly can if you just imagine that this is the case. Create two instances of a sprite. Create two instances of a js class. Done. They HAVE each other. Do whatever you want with them.

    I'd recommend you to think of a game object (not a class) as of a collection of two things:

    — a model that actually stores data, has methods that operate on its data, and virtually represents a game object

    — a view that visually represents a game object for a person who's looking at the screen

    If you're using javascript and classes and objects, a model is a js-object. A view is a sprite or a collection of sprites.

    If you have a good architecture, a game object has only one model and one view. When the model changes, the view should be updated (or update itself). In this sense, a view and a model should be somehow virtually connected so the view could update itself according to a certain model. A view should somehow address the model to get its data.

    If we're talking about game objects that have only one instance in the game, like Player, you just make the Player's view address the Player's model by remembering that the model is stored in the variable named "player". And that's it. There's no point of storing this name anywhere on the Construct side, because you'll eventually have to do JS.Call "player.update" and it's easier than doing JS.Call PlayerSprite.object_variable_name & ".update".

    But if we're talking about game objects that exist in plural, like enemies, then you're probably creating the js-objects and sprite instances dynamically. Then it makes sense to store js-objects in the array or something and then give every sprite the instance variable, like, "index" and set it to it's js-object's index in the array so you can later do:

    Enemy - on collision with - Bullet: JS.Call "Enemies_arr[" & Enemy.index & "].get_hit"

    Ooooor if you have to do this often and you came up with the handy js-wrapper:

    Enemy - on collision with - Bullet: JS.Call "EnemyManager.get_hit"(Enemy.index)

    If you're really interested in creating an elegant architecture using javascript, read this: en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

    And for the love of god read the manual: readymag.com/valerypopoff/valerypopoff-js-plugin I specifically illustrated there the very thing that you're asking about.

  • hugone I'd suggest you ask around in the Construct Discord community. People discuss stuff like that all day long there: discord.gg/HnuhDR

  • valerypopoff

    To access Javascript Variable:

    JS.Value("global_variable")

    JS.JSCodeValue("global_variable")

    Both does the same thing, so...why ?

    They work differently.

    JSCodeValue just evals the string you pass to it. So it can be any valid javascript you can think of. Using eval is not a great idea. Also eval is slow. So do it at your own risk.

    Value doesn't use eval and parses the js-expression that you pass to it. Js-expression can contain:

    • alias
    • global var-variables (not let and not const)
    • global functions
    • ["brackets"], [0]
    • .dots

    Js-expression can't contain:

    • function calls
    • operators other than brackets and a dot, like +, – and stuff
    • window object

    Using "Value" is preferable. It's super quick and it's safe.

    I'd suggest you read the manual. It's all there: valerypopoff.ru/construct/js-plugin

  • Yep. You just didn't add the name of the script to "Script files" property of the plugin. You only added the script file to the project and the plugin has no way of knowing that. Your javascript is simply not added to the page. So the plugin says the truth: "global_variable is not defined" and other error messages.

    When you add the name of the script properly, everything works fine.

    Here is the file:

    http://cebion.epizy.com/test.capx

  • Toddler Well it's weird. I just tested it with javascript you provided and it works fine in both C3 and C2. Can you give me the project file that reproduces the problem?

  • Toddler With the new version of the plugin you can access js objects directly, with no aliases

  • Not sure I understand what you mean or what it has to do with the plugin.

    Is possible to load the JS inline instead of additional network request?

  • You see how this one new feature will run circles around the current "alias" nonsense ?

    Of course I can see that. The question is why would you want to declare a global variable in javascript and then access it from Construct when it's 100 times easier and more convenient to declare a global variable right in Construct. I cannot understand that. I can see lots of benefits of using Construct global variables:

    — You can declare them and see their start values right in Construct

    — You can access them directly, no need to use any additional expressions or actions

    — There's auto completion that helps you to write the name of the variable

    — You can edit it's name and it changes everywhere automatically

    I can't think of any benefits that you can get by declaring global variables in javascript. Can you explain why you want to do this? Why is it more convenient to you?

  • Toddler Look.

    I want to make the plugin better. And I can't do this without asking people what they like or dislike about it. But implementing everything people are asking for is no way to do it, I think you know that.

    I keep telling you that you're probably using the plugin wrong hoping that you would either start using the plugin as intended and not have problems, ooooooor tell me what is it you're trying to achieve that is not possible to do the intended way.

    I can't implement a feature just because you think something is silly. But I can do it if I see that there's a way of using JS from Construct that I didn't think of.

    "Wanting to do something" is not a way of using, I can't accept this as a feature request. Can you tell me why is it that you need to have lots of global variables in JS and then access them from Construct? What are you trying to achieve by that? I need to understand that. Please cooperate.

    And yet it is possible to have functions within functions in JavaScript, you knew how silly it will be if you were to implement alias to functions, but you insist on not having a non alias way of accessing variable data.

    If you mean calling a function that has just been returned from another function, then it's not possible even with aliases and it wouldn't be possible even if I implemented no-aliases variable access that you're asking for.

    If you mean functions that are not global, you can still call them with no aliases: JS.CallFunction("Obj.functions_array[0]")

    you are utterly insistent on "All scripts loaded" being by default a continuous trigger [which makes no sense to anyone besides you] and yet knowing that by your own logic, construct 2's internal "On loader layout complete" would be a continuous loop which of course, would be utterly retarded if it was so.

    Why do you keep saying that "All scripts loaded" is a trigger? It's NOT a trigger, it's a condition. Triggers have a green arrow next to their name in the event sheet and their names start with "On".