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:
function getGlobalObject(name) {
var runtime = document.getElementById('c2canvas').c2runtime;
for (var p in runtime) {
if(Object.prototype.hasOwnProperty.call(runtime,p)) {
var prop = runtime[p];
if(prop === undefined) continue;
if(prop === null) continue;
if(typeof prop !== 'object') continue;
if(prop.length === undefined) continue;
for(var i = 0; i < prop.length; i++) {
if(prop[i].parent !== undefined &&
prop[i].data !== undefined &&
prop[i].sheet !== undefined &&
prop[i].name !== undefined) {
// probably the global var array
if(prop[i].name === name) {
// that one!
return prop[i];
}
} else {
// no need to loop if not global var array
break;
}
}
}
}
return null;
}
function setGlobalVar(name,value) {
var g = getGlobalObject(name);
if(g === null) return;
g.data = value;
}
function getGlobalVar(name) {
var g = getGlobalObject(name);
if(g === null) return 0;
return g.data;
}
setGlobalVar('myGlobal',4); // here is where you set your global
[/code:1ve38njy]
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 search
Then 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.