Game Development Community

Creating objects through scripts in the mission editor

by Stephan - viKKing - Bondier · in Torque Game Engine · 10/17/2007 (8:46 am) · 11 replies

I am looking to create objects through scripts into the mission editor. Of course, I do need to have created objects to be saved with the mission in the end.

My concern is about .dts objects.

Any input greatly appreciated - my brain needs a rest. ;)

Thanks for your time.

#1
10/17/2007 (9:18 am)
I'm not quite sure what you mean here.

Objects (essentially models) must exist first, and then can be placed in your mission using the editor.

I could be missing your objective. Please clarify if you can.
#2
10/17/2007 (9:31 am)
I know I can place objects within the editor, and of course, they are already existing and can be accessed through a path.

I really mean placing objects by script, yes. ;)
For example, placing an object 10 times, and no, copy and paste is not a valid option. :)
#3
10/17/2007 (9:50 am)
Check out this thread,

www.garagegames.com/mg/forums/result.thread.php?qt=30390

It talks about a ForestPack, and possible options.

This one,

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13325

I found in the above thread about the ForestPack. You should be able to do something with this.
#4
10/17/2007 (11:00 am)
@Kevin thanks, but not really what I'm planning to do.
I'm really looking into avoiding fxShapeReplicators (server/client system).

Let's hope someone with the knowledge will take a look a the post. ;)
The worst is that I'm about sure it is not that complicated.
#5
10/17/2007 (12:20 pm)
Got it!, it was too easy... I was looking for something more complex as usual.
Thanks for your time Kevin.
#6
10/17/2007 (12:21 pm)
Glad it was that easy. You'll have to post about it sometime, as I haven't gotten
into such things yet. Although I know I will.
#7
10/17/2007 (1:26 pm)
Easy, well not that much, I'm willing to use script to do that for months, but never really looked into. ;)

Currently, I can't create my script generated objects into simgroups.
#8
10/17/2007 (2:17 pm)
@STef

If you get that figured out let me know. I tried to figure out a way to add stuff created in script to simgroups and just couldn't find a way to do it. Our workaround, which may or may not help you, was to create the entire group and all the objects in at at once, using the exact same syntax used in the .mis files.

function createStage(%stagename, %atPos, %menuBar, %menu) {

	new SimGroup(%stagename) {
      new SimGroup(P1) {
         canSaveDynamicFields = "1";

         new SpawnSphere(spawn) {
            canSaveDynamicFields = "1";
            Position = VectorAdd($PositionP1[0], %atPos);
            rotation = "-0.0211759 0.796149 -0.60473 5.03632";
            scale = "1 1 1";
            dataBlock = "SpawnSphereMarker";
            Radius = "100";
            sphereWeight = "100";
            indoorWeight = "100";
            outdoorWeight = "100";
         };
         new MissionMarker(P1highandright) {
            canSaveDynamicFields = "1";
            Position = VectorAdd($PositionP1[1], %atPos);
            rotation = "0.52777 0.220727 -0.820207 54.0344";
            scale = "1 1 1";
            dataBlock = "CameraMarker";
         };
   ...
#9
10/17/2007 (3:26 pm)
@Ed: sure.
I found it. Ok, The Game's Programmer Guide To Torque helped a bit.

You need to declare a local variable for your SimGroup: i.e. %MyGroup = new SimGroup()
and for each object too... I don't mind as I'm generating objects using a "for" loop.

Base code isn't mind (it's Sam's), so I can't share it, anyway here is an example:
%MyGroup = new SimGroup();
    for (%i=0; %i<%x; %i++) {
    %MyObject = new TSStatic() {
    blablabla
    ...
    };
    [b]%MyGroup.add(%MyObject);[/b]
    }
%FSS0.add(%MyObject); with this, you are requesting to add the given object to a given group.

Maybe a bit more complex without a "for" loop. (Edit fixed sentence!)
I'm looking forward better integration of that. ;)
#10
10/18/2007 (7:05 am)
Great! Thanks STef!
#11
10/18/2007 (7:21 am)
Other Methods:

Add
BringToFront
Clear
Delete
Dump
DumpClassHierarchy
FindObjectByInternalName
GetClassName
GetCount
GetDynamicField
GetDynamicFieldCount
GetFieldValue
GetGroup
GetID
GetInternalName
GetName
GetObject
GetType
IsChildOfGroup
IsMember
IsMemberOfClass
IsMethod
ListObjects
PushToBack
Remove
Reorder
ReorderChild
Save
Schedule
SetFieldValue
SetInternalName
SetName