[Plugin] JavaScript (C2 and C3)

2 favourites
From the Asset Store
A cool way for kids to write and practice English Alphabets
  • 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.

  • Man I hate to put it to you like this man but I am SICK of your condescending attitude.

    First of all you should thank the people here who have been helping you improve your plug-in instead of constantly berating whether they can pick up a spoon every time they are asking a question.

    I am so SICK of your attitude that I really hope I can restraint myself from replying to your thread ever again.

    Frankly, you are not that smart yourself, your code is an extrapolation of at least three existing construct 2 plug-in on further inspection and you did NOT once give ANY credit to the developer you rip the idea off of, I am not going to name names, you really should do the right thing yourself before you got found out anyways.

    ========================================================================

    One:

    valerypopoff

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

    ========================================================================

    First of all, it means EXACTLY what I say it means, I said it is a form of "extends", let me just bring out one example, this applies to any programming language that support it and not just AS3.

    adobe.com/devnet/actionscript/learning/oop-concepts/polymorphism-and-interfaces.html

    Notice method two, the usage of "extends" to create Polymorphism.

    So, to use the same attitude you have been using towards everyone here, do you even know what Polymorphism is ?

    The audacity to say it have nothing to do with extends is not only incorrect, but misleading to anyone who is trying to learn programming beyond drag and drop Construct 2.

    You are not really as smart as you paint yourself up to be so I would suggest your tone down your baseless constant need to put people down.

    ========================================================================

    Two:

    valerypopoff

    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.

    ========================================================================

    That would defeat the very purpose of object orientated programming, that would defeat the whole reason why I would even create a class for a sprite in the first place which is what your plug-in will be use for.

    The idea is for every new sprite/object spawned, it will have its own base class during runtime, not just and only during editing.

    You mentioned your plug-in is to be used for the "view-model-controller" model, I hate to break it to you man, but since you are absolutely insidious on anyone who even ask you a question, any question at all and have seemingly no respect to your user at all, I am going to give you a feel of your own speech and to you, do you even know what true view model controller actually is ?

    I have been programming using Objective-C using XCode and the way it works is the true assertion of the "model-view-controller" framework and your plug-in ain't it.

    Your plug-in could be used to extend a sprite, but seeing that your answer is first to insult my intellect and then proceed to say the most ridiculous answer which is manually create a class for each object during editing time, dude, all I am going to say is, you are really not as smart as you make yourself up to be and that is putting it mildly.

    I am done with your condescending attitude and I am going to restrain myself from replying from now on.

  • Toddler Thanks!

  • Hey, this is a really great plugin !

    I managed to got it working with variables / floats. So importing my *.js file into the scene works ! I just got some questions:

    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.

    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.

    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)

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

  • Okay.

    Thx for clarification. I guessed it, that you can´t call a Sprite. Anyways. You can get around, by using functions ! I just thought to "directly" use JS-code to manipulate a Sprite.

    2.) Ah ok, guessed it too. As we can include as many *.js files into our scene, as we want, is it clever to to put all your logic into "one" *.js, or can you use different *.js for different tasks ? Like : "run.js", "camera.js", etc ...

    Manual / API:

    "...What else do you want it to cover? ...". All the commands for an external-JS isn´t on the link you provide. F.E. i can´t find anything like this "c2_callFunction(func_name, args_array);" in the so called "documentation"-link. There are just 2x-3x "small bitmap-pics" that barely describe some stuff. Thats all. There is 1x example.capx, i think. But its not done in different example.capx files, what would be much better, imho.

    I also don´t get it, if you wrote something like "func_name, args_array". Therefore i need "real_names" in an explaination, that refer to a other "real_name" and so on. Maybe you can take a look at some other API-documentations of other GameEngines.

    I only found important stuff in this forum here. Just wantet to give positive-critic. I am not a super power user in "JavaScript" ! Just learning it. And yeah, its maybe not that important for you, if you don´t want to reach many users, etc. Can understand it.

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

  • I guessed it. Yeah...i take it as it is, and i am thankfull. Cheers. But i will ask you again some questions ;-)

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

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

  • 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
    
  • Got it thanks. It's so useful, I'd hate to see it go away, glad to hear there is a solution (though not as compact as the current event/action of course.) As you say in the description if there's a decent amount of JS code behind each call, the overhead for adding params will be small.

    I've been using it to test the GameSparks JS API with C3 runtime (since there's not a C3 runtime plugin) and it was so easy to get it up and running with your plugin!

  • what'S a variadic condition or action ?

    It's a condition or action where you can add parameters with "+" button like when you call a function in Function plugin

  • valerypopoff

    Hi thanks for your plugin.

    Your plugin not working well if I add the NEWjs plugin. I want to export my application for windows. This seems to disrupt the JavaScript function call

  • Try Construct 3

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

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

    Hi thanks for your plugin.

    Your plugin not working well if I add the NEWjs plugin. I want to export my application for windows. This seems to disrupt the JavaScript function call

    What's a "NEWjs plugin"?

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