Fabian said:
I have a three tier nested array, used to define a map for a javascript
game, and can be edited within the web page. Is there a way I can
generate a visible copy of this array that I can then c&p into a file? I
think the best solution would be to write into a popup window (this
popup would be purely for map development use, so I don't feel worried
by popup blockers, as only myself would be seeing the popup). However, I
have no idea how to:
a) create the string in a form that a html parser can display as
ready-formatted javascript code
b) generate the popup
This creates an array with fixed dimensions, but the show() function
works with whatever dimensions it finds. I believe <xmp> is deprecated,
but since this is just for development work, you probably don't care.
<html>
<head>
<script type="text/javascript">
// initialize 3D array with sequential integers
map=new Array();
count=0;
for(var i=0;i<5;i++){
map[i]=new Array();
for(var j=0;j<5;j++){
map[i][j]=new Array;
for(k=0;k<5;map[i][j][k++]=++count);
}
}
function show(f){
f.info.value=map[f.indexi.value][f.indexj.value][f.indexk.value];
}
function update(f){
map[f.indexi.value][f.indexj.value][f.indexk.value]=f.info.value;
}
function display(){
globalOutput="<html><body><xmp>";
globalOutput+="map=new Array("+map.length+");\n";
for(var i=0;i<map.length;i++){
globalOutput+="map["+i+"]=new Array("+map[i].length+");\n";
for(var j=0;j<map[i].length;j++){
globalOutput+="map["+i+"]["+j+"]=new Array("+map[i][j].length+");\n";
for(var k=0;k<map[i][j].length;k++){
globalOutput+="map["+i+"]["+j+"]["+k+"]=\""+map[i][j][k]+"\";\n";
}
}
}
globalOutput+="</xmp></body></html>";
window.open("javascript
:opener.globalOutput","popu p");
}
</script>
</head>
<body onload="show(document.forms[0])">
<form>
<input name="indexi" value="0" onchange="show(this.form)">
<input name="indexj" value="0" onchange="show(this.form)">
<input name="indexk" value="0" onchange="show(this.form)">
<input name="info" value="">
<input type="button" value="Update" onclick="update(this.form)">
<br>
<input type="button" value="Display" onclick="display()">
</form>
</body>
</html>