<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: multiple object instances with javascript</title>
		<atom:link href="http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 16:54:47 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-60067</guid>
					<title><![CDATA[multiple object instances with javascript]]></title>
					<link>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-60067</link>
					<pubDate>Thu, 17 Nov 2011 10:16:04 +0000</pubDate>
					<dc:creator>foobert</dc:creator>

					<description>
						<![CDATA[
						<p>is there a way to actually create an on &#8220;bang&#8221; without deleting the other instances? meaning: can i create more than one object with javascript?<br />
i tried this javascript code, but it replaces the previously drawn object with a new one.<br />
any ideas?</p>
<p>function bang()<br />
{</p>
<p>// generate a random text<br />
var text = &#8220;&#8221;;<br />
var possible = &#8220;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&#8243;;<br />
for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length));<br />
var randomnumber=Math.floor(Math.random()*999999);</p>
<p>var mywidget[randomnumber] = new JitterObject(&#8220;jit.gl.gridshape&#8221;,&#8221;jgm2&#8243;);<br />
mywidget[randomnumber].shape = &#8220;cube&#8221;;<br />
mywidget[randomnumber].lighting_enable = 1;<br />
mywidget[randomnumber].smooth_shading = 1;<br />
mywidget[randomnumber].scale = [6,6,6];<br />
mywidget[randomnumber].color = [1,1,1,0.5] ;<br />
mywidget[randomnumber].blend_enable = 1;<br />
mywidget[randomnumber].position = [1,1,1];<br />
mywidget[randomnumber].name = text;</p>
<p>mywidget[randomnumber].lighting_enable=1;<br />
mywidget[randomnumber].blend_enable=1;<br />
mywidget[randomnumber].smooth_shading=1;<br />
mywidget[randomnumber].depth_enable=1;<br />
mywidget[randomnumber].material=&#8221;mtl&#8221;;<br />
mywidget[randomnumber].cull_face=1;</p>
<p>var x[randomnumber]= new JitterObject(&#8220;jit.phys.body&#8221;);<br />
x[randomnumber].shape=&#8221;cube&#8221;;<br />
x[randomnumber].targetname = text;<br />
x[randomnumber].scale = [6,6,6];<br />
x[randomnumber].worldname =&#8221;foobert&#8221;;<br />
}</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-216252</guid>
					<title><![CDATA[Re: multiple object instances with javascript]]></title>
					<link>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-216252</link>
					<pubDate>Tue, 17 Jan 2012 14:59:11 +0000</pubDate>
					<dc:creator>foobert</dc:creator>

					<description>
						<![CDATA[
						<p>*bump*<br />
is this really not possible with max6?</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-216253</guid>
					<title><![CDATA[Re: multiple object instances with javascript]]></title>
					<link>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-216253</link>
					<pubDate>Tue, 17 Jan 2012 17:52:04 +0000</pubDate>
					<dc:creator>Rob Ramirez</dc:creator>

					<description>
						<![CDATA[
						<p>i think your javascript is not correct.<br />
shouldn&#8217;t you be declaring your arrays like this?<br />
var mywidget = new Array();<br />
mywidget[randomnumber] = new JitterObject<br />
&#8230;.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-216254</guid>
					<title><![CDATA[Re: multiple object instances with javascript]]></title>
					<link>http://cycling74.com/forums/topic/multiple-object-instances-with-javascript/#post-216254</link>
					<pubDate>Wed, 18 Jan 2012 17:45:51 +0000</pubDate>
					<dc:creator>DiGiTaLFX</dc:creator>

					<description>
						<![CDATA[
						<p>How about this? I can&#8217;t see what your code is doing without the rest of the patch but I think this should do what you want :)</p>
<pre><code>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 &#39;randomnumber&#39; 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
		}
}</code></pre>						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

