Game Development Community


#1
03/01/2005 (10:54 am)
Here's ya go. Scroll down - arrays are about 1.4 the way down

As for teh circle collision, use the setCollisionPolyPrimitive command with a value of like... I dunno - 12? 6-12? I don't know what the best number of faces would be.
#2
03/01/2005 (10:56 am)
@Robert:

To do arrays, use the "[]" notation. If you want to do multi-dimensional arrays, seperate the elements with the "," operator like so:-

// Build Array.   
	for ( %x = 0; %x < 10; %x++ )
	   for ( %y = 0; %y < 10; %y++ )
		$myArray[%x,%y] = %x SPC %y;

	// Echo Array.		
	for ( %x = 0; %x < 10; %x++ )
	   for ( %y = 0; %y < 10; %y++ )
		echo ( $myArray[%x,%y] );

With regards to T2D and trivial collision-detection, we toyed with the idea of making the collision detection use box/circle detection and then have the user turn-on swept-poly detection but this was just another call you'd have to make. In the end, we got the collision-detection running in a fast two-phase method which although doesn't make having circle-circle collision obsolete, they'd have to be swept-circle collision as we're doing sweeping of all stuff here.

In the end we decided to go with the more expensive but far superior swept convex polygon detection and it is fast. Use something like:-
%object.setCollisionPolyPrimitive( 16 );

... with more/less polygons until you're happy. All the pool balls in the pool demo use this method. They have polygons with 24 side as those collisions need to be particularly precise. Typically though, you'd probably use swept circle-circle collisions (capsules) for stuff like pool but we get away with here because the system is particular fast.

Really, don't worry about stuff like this unless it becomes a problem. Just assume T2D is going to be fast enough.

- Melv.
#3
03/01/2005 (10:57 am)
Drew beat me. :)

- Melv.
#4
03/01/2005 (12:15 pm)
@Robert: Switch off your targetting computer and trust the "force". :)

You need to use ScriptObjects.

There's also a mention of them here in the T2D forums.

You can create dynamic-fields, as you've probably seen. Something like this...

// New Sprite.
fxStaticSprite2D(mySprite) { blah blah blah };
mySprite.myDynamicField = 100;

"myDynamicField" is, you guessed it, a dynamic field. The reason you can do this is because the T2D objects inherit those abilities from the core. If you create a dynamic-field yourself, you can't do something like...

// New Sprite.
fxStaticSprite2D(mySprite) { blah blah blah };
mySprite.myDynamicField = 100;
mySprite.myDynamicField.myOtherDynamicField = 200;  // Not Allowed!

So you don't have to create a T2D object all the time, you can create a ScriptObject which is a light, lazy object but certainly not useless. It has the ability, just like any T2D object, to have dynamic-fields hanging-off it. It also has extra abilities such as defining a namespace so you can base member functions on it like so:-

function doStuff()
{
   $obj = new ScriptObject() { class = myClass; };
   $obj.dynamicField1 = 100;
   $obj.dynamicField2 = 200;
   $obj.dynamicField3 = 300;

    $obj.run();
}

function myClass::run( %this )
{
   echo( %this.dynamicField1 );
   echo( %this.dynamicField2 );
   echo( %this.dynamicField3 );
}

... or in your case ...
function doStuff()
{
  // Build Array.   
   for ( %x = 0; %x < 10; %x++ )
   {
      for ( %y = 0; %y < 10; %y++ )
     {
        $myArray[%x,%y] = new ScriptObject() { class = myFieldClass; };
        $myArray[%x,%y].dynamicField1 = 100;
        $myArray[%x,%y].dynamicField2 = 200;
        $myArray[%x,%y].dynamicField3 = 300;
 
         // Wow, even....
        $myArray[%x,%y].dynamicField4 = new ScriptObject() { class = myFieldClass; };
        $myArray[%x,%y].dynamicField4.childField1 = 100;
        $myArray[%x,%y].dynamicField4.childField2 = 200;
        $myArray[%x,%y].dynamicField4.childField3 = 300;

        $myArray[%x,%y].dumpFields();
     }
   }
}

function myFieldClass::dumpField( %this )
{
   echo( %this.dynamicField1 );
   echo( %this.dynamicField2 );
   echo( %this.dynamicField3 );
   echo( %this.dynamicField4.childField1 );
   echo( %this.dynamicField4.childField2 );
   echo( %this.dynamicField4.childField3 );
}

The only thing you need to be careful with is that, like anything in TorqueScript, you delete these objects when you're finished with them. Deleting something referencing them won't work. A quick way is to use SimGroups/SimSets (see doco).

Hope this helps,

- Melv.