Problem:This doesn't seem to change the global variable in Construct2 when the function call is made. It does initially make the call and create the menu to accept or cancel it but once again it doesn't change the variable when the function is called. Is there another way to accomplish this?

Such as declaring a variable within the execute javascript command?

Last edited by retrodude on Sat Mar 08, 2014 8:15 pm, edited 1 time in total.

You can still access global variables using the execute javascript command in construct2. I'm wondering how I can directly change the value of the global variable using the javascript browser command in the events.

Can the execute javascript command use system function expressions from C2? I tried creating a function called "p" which set's the sprite objects opacity to 100 when called. I also created a function called"q" which sets the objects opacity to 0.

{"&premium=1&"} is interrupting the string of the execute javascript I think, as well as {"&premium=2&"} so I am missing totally the purpose of this. What this {"&premium=1&"} and {"&premium=2&"} are supposed to do?

If they are supposed to set the value, then you should do on function "p": set premium value to 1on function "q": set premium value to 1

you might want to set return values too, but I don't know exactly so..

Changing the value of a global variables is way more complex than what you think. Global variables in construct2 aren't javascript variables, they are objects with, amongst other things, "name", "data", "initial" properties.They are indeed in the all_global_vars array of the c2runtime.

But the big problem is that when you export your project, a lot of that stuff gets minified.

Nonetheless, it seems there's enough to write something that can parse the runtime and find the objects which "look like" global variables and then narrow down the search on the name.Here is what you can put in the Browser Execute javascript:

This code gets the runtime from the canvas (assuming it has the id "c2canvas")Then go through all the properties looking for arrays (which are objects with a length property)And then loop through all the element of the array to find objects with parent, data, sheet and name properties.Those properties are hopefully not minified (at least for now) and it seems enough to narrow down the searchThen just checking for the name property gives you the proper global variable object you can get/set.

As a word of advice, don't do that everytick... I don't think it's super efficient. Also... You should probably make a plugin for that kind of stuff. Since the plugin code gets minified the same way, you get something more reliable.