Game Development Community

Declare a class in script

by Luis Anton Rebollo · in Torque Game Engine · 03/17/2005 (12:59 pm) · 16 replies

It's possible declare a class in script without limitations, similar than datablocks.

Script object can't use a somes classes (ShapeBase etc...) as class or superclass.

In torque documentation:

Objects are created in TorqueScript using the following syntax:

            // In TorqueScript
            %var = new ObjectType(Name : CopySource, arg0, ..., argn) 
            {...

...
ObjectType- Is any class declared in the engine or in script ...

They are other possibilities?

Thx to all.

#1
03/17/2005 (1:17 pm)
Luis i'm afraid I don't really understand what it is you are looking to do. Perhaps if you can explain what you are trying to accomplish?

ScriptObject is nothing more than a generic class/object that is pretty much fully controlled/configured as it were in the script code. Besides SciprtObject there are tons of other classes built into Torque that you can use in script, and you can always add your own as well (See my resource on the subject about adding your own if that is what you want to do).
#2
03/23/2005 (2:52 am)
@john
i am also looking to make an object containing structure like


object(Response)
- Sentance1(string)
- text
- sound file
- Sentance2
.......
.......
......


Now i want to make an function that take an args of response object and according to object containing sentances with related text and sound to show and play respectively in order as sentance1,sentance2 etc..

give me the suggetions how to start proceding with that.
#3
03/23/2005 (3:07 am)
%obj = new scriptObject(Response)
{
   Sentence1 = "This is a sentence";
   Text = "This is text";
   sound = "sound/file/name.ogg";
};
#4
03/23/2005 (3:18 am)
Thanks. but where to write these objects and how these objects are passed as parameter to a function and where will be the function. i am new to this so i have no idea about that. can you explain this, it will be greate help for me.
#5
03/23/2005 (10:18 am)
The ScriptObject and ScriptGroup classes have a "class" and "superClass" field you can use for this purpose:

$foo = new scriptObject()
{
   class = response;
   text = "I'm foo";
}

$bar = new scriptObject()
{
   class = response;
   text = "I'm bar";
}

function response::getText(%this) {
   return %this.text;
}

echo($foo.getText())
=> "I'm foo"

echo($bar.getText())
=> "I'm bar"
#6
03/31/2005 (8:48 am)
Thx Manoel :)
#7
04/20/2005 (3:55 am)
Is it possible to delete a class, once its made? Or delete a ScriptObject? Like it is done in c++ ( delete $foo; ).
#8
04/20/2005 (3:57 am)
Youre not deleting a class, youre deleting an objet.
#9
04/20/2005 (4:00 am)
Would it be possible, to have some functions in a Group/Class/Object and be able to delete them? I'm trying to have a set of functions be able to be deleted.
#10
04/20/2005 (4:30 am)
There is probably a wayt od o that using a simSet (or simgroup)... You can delete an object via script through %obj.delete (I think) or setting it to 0.. You may be able to use the simset functions to delete everything in the group
#11
04/20/2005 (5:12 am)
Can i setup the simset/group to run a function? Maybe the namespaces/sims are linked?
#12
04/20/2005 (5:51 am)
I dont know. You should look at teh source to see what you can call and what each funciton does.
#13
04/20/2005 (5:57 am)
SimGroup::removeObject(SimObject* obj); You can write a funciton in the source and expose it to the console... Example: SimGroup::DeleteAll() which will delete everything... or in script MyGroup::ILikeTorque(){ .. }
#14
04/20/2005 (3:22 pm)
Functions are not meant to be deleted. If you have to "get rid of one" why not just redefine it to do nothing?
#15
04/21/2005 (5:14 pm)
@Ben hey I thought you went on vacation or something. :)
#16
04/21/2005 (11:45 pm)
I did. I'm back now. I've been back for about three weeks.