Game Development Community

Generate a level from script

by Patrick Shaw · in Constructor · 07/07/2008 (5:47 am) · 5 replies

I would like some advice for how to use Torque Script (TS) to create an interior level from a text file. Specifically, I would like to know:

a) What are the TS commands for loading prefab and DTS shape?
b) What are the pros/cons of using prefabs vs. DTS shapes?

The reason I need to know this is that I am working on re-creating "Alternate Reality", a 3D CRPG from 1985. The game is set in a large (for 1985!) fantasy city with shops, taverns, etc. I have the map data exported as a text file from the original game. I would like to use this data to automatically build a DIF version in Constructor.

I am familiar enough with TS to load the text file and parse it. Looking through the included scripts, I can get as far as adding simple walls. However, creating anything else more complicated seems laborious. Ideally, I would like reference an external file for each of the walls, doors, pillars, etc. I could use DTS shapes or Prefabs, but I can't find how to do this in the documentation and scripts that come with Constructor are quite complex. Any help or insight you may have would be appreciated!

#1
07/07/2008 (8:54 pm)
Are you going to create these in constructor? Or in TGE/A? Constructor has been modified quite a bit, and supports adding primitives, etc. TGE/A does not have all of the features for editing that constructor has.

However, you can easily create shapes in TGE or TGEA at run time - Check out the latest PlasticGames resource, it shows just how to do it.
#2
07/08/2008 (3:44 am)
Jaimi,
I am doing this in constructor because performance of a single DIF is much better than 1000+ simple shapes. I wrote a script for the creating the shapes in TGE and the resulting level was just way too slow.
#3
07/08/2008 (8:46 am)
OK - that's easier then. To create brushes on the fly, you would do this:

%newbrush = new MapBrush();
%newbrush.setOrigin(%center);


// how to add a face to a brush. You'll need to do this once per face. This method
// is using the vertexes on the polygon to define the plane (3 are enough).
%newbrush.setTexturePlanesByPoints(%vertpos1, %vertpos2, %vertpos3, 0.0, 0.0);
%newbrush.addPlaneByPoints(%vertpos1,%vertpos2,%vertpos3);

// Once you're done adding faces, then update it, you're done!
%edit.updateBrush(%newbrush);

To add a prefab is even simpler - do this:

%prefab = %edit.addPrefabToBuffer(prefabfile); // prefabfile is the full path and filename of the prefab
%edit.setPrefabOrigin(0, %pos); // set the position. Pos is a x SPC y SPC z.
#4
07/10/2008 (2:43 pm)
Jaimi,
Thanks. The prefab method is preferable. However, I'm not sure how to use your script sample. %edit is a local variable - what object does it point to?
#5
07/10/2008 (2:47 pm)
You'll need to do this in the context of a plugin. Take a look at the plugin script that makes boxes, you'll see how it gets the %edit variable.

Jaimi