valerypopoff's Forum Posts

  • Toddler I don't understand what you have against aliases. It's convenient, look:

    Even if you have a complicated structure of game objects, like:

    var MainObj = 
    {
    	players_arr = 
    	[ 
    		{
    			name: "Pacman",
    			health: 100
    		}, 
    
    		{
    			name: "Inky",
    			health: 100
    		},
    
    		{
    			name: "Blinky",
    			health: 100
    		},
    
    		{
    			name: "Pinky",
    			health: 100
    		},
    
    		{
    			name: "Clyde",
    			health: 100
    		}
    	]
    }
    

    You can do:

    JS.InitAlias "Pacman" with javascript "MainObj.players_arr[0]"

    JS.InitAlias "Inky" with javascript "MainObj.players_arr[1]"

    JS.InitAlias "Blinky" with javascript "MainObj.players_arr[2]"

    JS.InitAlias "Pinky" with javascript "MainObj.players_arr[3]"

    JS.InitAlias "Clyde" with javascript "MainObj.players_arr[4]"

    And later operate with "Pacman", "Inky", "Blinky", "Pinky" and "Clyde" without this long "MainObj.players_arr[n]".

    If you have game objects in JS, they should be represented with classes, not with global variables. Since you have game objects in classes, it's not a problem to make aliases for them. It's not like it's 100 of them. It's like 3, right?

    If you have a problem using aliases, you're probably doing it wrong.

    If you have lots of global variables that are not objects and you want access them from construct, you're doing it wrong. It makes no sense since there are variables in Construct. No need to store global variables in js when you can do this in Construct directly.

    Instead you're supposed to have objects in js — the thing that you can't have in Construct. If you have lots of global variables that are objects, you're doing it wrong. Even if you have a game with 30 different enemies, they shouldn't be stored as 30 global objects. They should either be stored as an array of 30 objects, or be scripted in such a way that you don't need to access them at all.

  • Toddler

    Can I use class ? I really want to use class...it's more OOP like.

    Yes. You can use any valid JavaScript. I didn't use class because not all browsers support it. For example, some old Androids with webview 30- (or such).

    The only thing that the plugin doesn't see is global variables with const and let. Shouldn't be a problem.

    You can even call object functions like this: object1.function1.

    You can even call object functions like this: object1.propery['one']['two'].foo['bar'].function1

    Return value can be accessed via JS.StoredReturnValue.

    Or you can compare returned value right away with conditions like Compare Function return value or Compare alias call

    Since StoredReturnValue contains only string, use JSON to transfer your data.

    That's not true. StoredReturnValue contains any Construct data type. It means it can be string, integer or float (boolean will be converted to 0/1). There's no need to use JSON. If you have to transfer data to Construct in JSON format, you probably have a wrong architecture. The only valid reason for retrieving JSON from javascript is when you want to put it to JSON plugin. But in this case you're actually passing some string. It just happens to be JSON.

    Now the second question is, can you create a trigger from a javascript file ?

    Sure. You can call Construct functions from javascript like this:

    c2_callFunction(name, args_array)
    

    I came up with this wrapper:

    function ConstructCallback(name, args)
    {
    	if( name == "" )
    	return;
    	
    	args = (args === undefined) ? [] : args;
    	
    	if( c2_callFunction !== undefined )
    	{
    		return c2_callFunction(name, args);
    	}
    
    	if( c3_callFunction !== undefined )
    	{
    		return c3_callFunction(name, args);
    	}
    }
    

    ConstructCallback triggers Construct function and even gets the return value from Construct that you can use in JS if you like.

    Question 1: Why is "All scripts loaded" continuously triggering ?

    Because it's not a trigger. It's a simple condition. Don't confuse one with another. Once scripts are loaded, All scripts loaded is always true. If you want to make a trigger out of it, add Trigger once (see the example on the promo page). I just didn't want to make a trigger condition since it is so easy to do it yourself.

    Question 2: Can we have js.variable_value("enter variable name here") instead of js.AliasValue("enter the alias name here") ?

    You sure can. Just use Execute JS code action or JSCodeValue expression or Compare JS code completion value condition. You can pass pure javascript to them. The problem is that it's only possible because they work by eval'ing those strings. And this is not a very good practice.

    The alias system is there for a reason. When you do

    js.InitAlias "Alias" with javascript "foo"

    js.AliasValue("Alias.bar")

    It actually translates to window["foo"]["bar"] on runtime. This is 100 times faster than eval'ing the string "foo.bar".

    Getting back to your question. I could make actions, conditions and expressions that work exactly like Aliases but you don't have to init the alias first. But it would mean +10 ACEs the user would need to learn to use.

    If you have lots of global variables (which is weird) that you want to access from Construct, just do

    js.InitAlias "Global" with javascript "_window"

    And add this to your javascript:

    var _window = window;
    

    Now you can access all global variables with alias "Global": js.AliasValue("Global.foo")

    Question 3: Now this is difficult I think...can you somehow create a way for the custom javascript to have its own triggers ?

    What do you mean "its own triggers"? You mean make javascript code tick itself? Well you sure can use SetInterval function for that. But I can't even imagine why would you want your javascript code to have ticks. Javascript code is a model of your game objects. A model doesn't tick. A model stores data and makes actions (changes itself) when you ask it to. There should be only one ticking mechanism in the game and you already have it: it's event sheets. But you're still free to use any async things in your javascript.

  • Toddler Damn, those are pretty high expectations)

    Yes, the main reason I made this plugin was that I wanted to have game objects in JS. With constructors and stuff, you know. It especially works well if you follow MVC paradigm: model goes to JS files, view and controller stay in Construct. There's a player object in JS with lives and points. This object doesn't know (and shouldn't know) anything about the player sprite and its current animation. View (construct event sheet) checks js object's state every tick and changes animations if needed. Actions like jumping don't change js object, they only affect player's sprite. And only if the sprite hits the enemy, Controller (event sheets) calls player object's methods like player.hit(). A method changes the object's state. The View checks the object's state and changes animations if needed. And so on.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok I looked at the project file and I know why it doesn't work. You simply didn't tell the plugin what scripts to load. You have to put the name of the script to "Script files" property of a plugin in a Properties bar. You just added scripts to the project and the plugin has no way of knowing that.

    I believe you didn't read the documentation. Do this: readymag.com/valerypopoff/valerypopoff-js-plugin

    When you fix it, it works, but the canvas with the result is not visible and hidden under the game. If you go to the developer console and delete it, you finally get to see it. A small gray canvas the size of the button. It actually IS a button but without a caption on it:

    But if you take a screenshot of the whole <body>, you'll see this:

    Which is no surprise because this kinda tools are supposed to work with regular web-pages, not canvas-based games.

    It was nothing. Just trying to call a function when 'All scripts were loaded' fired. Nothing else.

    https://cdn.discordapp.com/attachments/508660646704054275/511517237954347018/html2canvasTest.capx

    I just made this now since you asked. I was checking the console for errors. It comes up as html2canvas is undefined.

  • Can you show me the project file?

    I just get 'html2canvas' is undefined. But I think that's more of an error in my part in trying to make it work with your plugin. And it's actually not a screenshot but just builds the representation of the page or element on a canvas. Again, I'm a noob at js and don't know what I'm doing.

  • Pandy

    I don’t have a reason to believe that this new instrument will work when the previous one didn’t. The fact that it takes a screenshot of the whole page doesn’t mean it works differently technology-wise.

    Anyways, what errors do you get?

  • And you're trying to take a screenshot of what exactly?

    valerypopoff

    html2canvas is a way of taking screenshots of form elements like buttons. Normally the paster plugin or the canvas snapshot feature can't paste or grab buttons, lists etc, but apparently this html2canvas does something to mimic these form elements in style and then takes a screenshot of it which we can use.

    I tried to use it, but honestly I haven't got the slightest clue how to get it to work or if it is even possible.

  • I don't know what is it that's below the link.

    But I can tell you that. With my plugin you can dynamically add the script to a webpage and access functions, variables and objects in it. Call functions, set variables and this kinda stuff. If that's what you're supposed to do with whatever that's below the link, then yes, it's possible to get it to work.

    valerypopoff

    Forewarning that I'm a noob. But can you tell me if it is possible to get the below to work in construct2 with your plugin? And if yes, how to do it?

    http://html2canvas.hertzen.com/

    https://github.com/niklasvh/html2canvas/releases

    Thanks

  • IS it ever going to support web workers ?

    I don't know. Not until it stops being an experimental feature in Construct. And why do you need web workers in the first place?

  • I'm working on my Tweening plugin and I was curious if I could store a finished tween's properties in this.FinishedTween, and then trigger OnFinished and let all OnFinished events access this.FinishedTween without having to worry about other Tweenings rewriting this.FinishedTween during the next tick.

    From what I understand, the next tick waits for all triggered events to finish first.

  • We have limited resources and can't do everything quickly (even if I wish we could!)

    If people vote on the suggestion then we are more likely to prioritise it, otherwise there are currently dozens of other things we have in-flight and I can't guarantee when we can look in to anything else in particular.

    I see. Don't you want to at least repromote construct3.ideas.aha.io It's been quite a while since it was introduced and collected lots of suggestions and voices. I, for example, didn't even know it still worked before I created this post. I thought it was just for the time you were in the very beginning of Construct 3 development.

  • Ashley did you decide anything?

  • Fixed the issue in Javascript Plugin v.0.6.7. Thanks for reporting!

    The problem was that hmmg_layoutTransition plugin used JQuery dependency. And when it's the case, Construct loads a slim build of jquery that has problems with AJAX.

  • does hmmg_layoutTransition use or connect jquery to the webpage?

  • It's defined in c2 as window["c2_callFunction"]. C3 is probably defined the same way.

    So if you're calling it from a plugin and want it to be minify safe use:

    window["c2_callFunction"]("my function",[])

    instead of

    c2_callFunction("my function",[])

    Hmm... is window.c2_callFunction also fine then?