Acessing java script objects/arrays from monkey

Monkey Targets Forums/HTML5/Acessing java script objects/arrays from monkey

Salmakis(Posted 2016) [#1]
Hi, im Stuck with some .js stuff and wanted to ask for the help of the monkeys =)
What do i need to do, when i want to access an Object or an Array of objects or primitives that is defined in some .js Code from monkey?

I figured it out with function() but not with stuff like arrays of primitives etc.
if i have the given .js code:

var data = "test"; //i can access this one :)
var Client = {}

Client.getTest= function() {
    return("test");//this one is working aswell :)
}

//the following is not working :(
Client.pageData = new Array(64);
for (var x = 0; x < 64; x++) 
{
	pageData[x] = new Array(64)
	for (var y = 0; y < 64; y++) 
	{
		pageData[x][y] = 1;
	}
}


with the following monkey-x code:
Extern
Global data :String 'works

Class Client= "Client"
	Function getTest:String() 'works
	Global pageData:int[][] 'this is dropping errors :(

End Class


as you see, i want to access an array (of arrays) out of ints, but when i try it like this, i get the error
"Monkey Runtime Error : TypeError: Unable to get property 'length' of undefined or null reference"
(even when i not acessed length...)
i tried it with other types of arrays aswell like float[][] and even string[][] but allways the same issue, can anyone help me out here?
any idea?

Edit: i just found it out by checking how monkey/trans compiler did this so if anyone else got this problem:

.js part:
Client.pageData = new Array(64);
for( var i=0;i<64;++i )
{
    Client.pageData[i]=[];
    for( var j=0;j<64;++j )
    {
        Client.pageData[i][j] = 4 
    } 
}



diemar(Posted 2016) [#2]
It's just a guess, but any javascript gobal object or variable that you created in monkey should be accessible in the html framework during its livespan.

for variables, monkey adds a prefix:

bb_sourcename_

Sourcename is eg. "test" if you're running "test.monkey".

Maybe it's a similar thing with arrays. Watch main.js to find your arrays etc. with an added prefix.

Sorry, just guessing here.