valerypopoff's Recent Forum Activity

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

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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

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