multiple object instances with javascript
is there a way to actually create an on "bang" without deleting the other instances? meaning: can i create more than one object with javascript?
i tried this javascript code, but it replaces the previously drawn object with a new one.
any ideas?
function bang()
{
// generate a random text
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length));
var randomnumber=Math.floor(Math.random()*999999);
var mywidget[randomnumber] = new JitterObject("jit.gl.gridshape","jgm2");
mywidget[randomnumber].shape = "cube";
mywidget[randomnumber].lighting_enable = 1;
mywidget[randomnumber].smooth_shading = 1;
mywidget[randomnumber].scale = [6,6,6];
mywidget[randomnumber].color = [1,1,1,0.5] ;
mywidget[randomnumber].blend_enable = 1;
mywidget[randomnumber].position = [1,1,1];
mywidget[randomnumber].name = text;
mywidget[randomnumber].lighting_enable=1;
mywidget[randomnumber].blend_enable=1;
mywidget[randomnumber].smooth_shading=1;
mywidget[randomnumber].depth_enable=1;
mywidget[randomnumber].material="mtl";
mywidget[randomnumber].cull_face=1;
var x[randomnumber]= new JitterObject("jit.phys.body");
x[randomnumber].shape="cube";
x[randomnumber].targetname = text;
x[randomnumber].scale = [6,6,6];
x[randomnumber].worldname ="foobert";
}
*bump*
is this really not possible with max6?
i think your javascript is not correct.
shouldn't you be declaring your arrays like this?
var mywidget = new Array();
mywidget[randomnumber] = new JitterObject
....
How about this? I can't see what your code is doing without the rest of the patch but I think this should do what you want :)
var mywidget = new Array();
var x= new Array();
function bang()
{
// generate a random text
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length));
var randomnumber=Math.floor(Math.random()*999999);
var widget = new JitterObject("jit.gl.gridshape","jgm2");
widget.shape = "cube";
widget.lighting_enable = 1;
widget.smooth_shading = 1;
widget.scale = [6,6,6];
widget.color = [1,1,1,0.5] ;
widget.blend_enable = 1;
widget.position = [1,1,1];
widget.name = text;
widget.lighting_enable=1;
widget.blend_enable=1;
widget.smooth_shading=1;
widget.depth_enable=1;
widget.material="mtl";
widget.cull_face=1;
var xt= new JitterObject("jit.phys.body");
xt.shape="cube";
xt.targetname = text;
xt.scale = [6,6,6];
xt.worldname ="foobert";
// adds the newly created objects to the ends of the arrays
mywidget.push(widget);
x.push(xt);
// removes the object at the start of the arrays if outside of your 'randomnumber' limit
if (mywidget.length > 999999)
{
mywiget.shift();
x.shift(); // assuming that these arrays are only altered here it is fine to remove the elements from this one in the same block
}
}