I'm learning javascript and I want to fill an array in one function and pass it as a parameter in the second function. I have the following code but for some reason it is not working.
function gameplay(tmp) {
for (var i = 0; i < tmp.length; i++) {
if (xTrans >= tmp[0] - 1
&& xTrans < tmp[0]
&& zTrans <= tmp[1] - 1
&& zTrans > tmp[1])
{
//some code here
}
}
}
function fillMap() {
var bounds = new Array();
for (var y = 0; y < map.length; y++) {
for (var x = 0; x < map[0].length; x++) {
if (map[y][x] == '1') {
bounds[length] = 4 * x;
length++;
bounds[length] = -y - 4 * y;
length++;
}
}
}
return bounds;
}
and I call like this:
var tmp = fillMap();
gameplay(tmp);
Thanks in advance..
lengthvariable is not defined. I assume you wantbounds.push(...)instead. If you are new to arrays in JS, I recommend to a tutorial: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/… .mapdefined?