Game Development Community

Instances of "ScriptObject

by Daniel Jami · in Torque Game Builder · 07/27/2007 (4:26 am) · 5 replies

Hi
i tryed to build my weapons like this:
new scriptObject() {
	class = weapon_ICE;
	power = 100;
	fire_speed = 100;
	misile_speed = 800;			
	level = 2;				
};
now i need to create multi instances of my "ScriptObject" , and i use this code:
function playerShip::setWeapons(%this) {
	%this.playerMissile[0] = new weapon_ICE();
}
but followeing error is result :
Unable to instantiate non-conobject class weapon_ICE.

how i cand create on object that i cand instantiate it !!

#1
07/27/2007 (10:24 am)
Try changing:

function playerShip::setWeapons(%this) {
	%this.playerMissile[0] = new weapon_ICE();
}

to

function playerShip::setWeapons(%this) {
	%this.playerMissile[0] = new t2dStaticSprite()
         {
            scenegraph = %this.scenegraph;
            class = weapon_ICE;
         };
}
#2
07/27/2007 (10:29 am)
To get your new missile using the defaults you are trying to create you can do somet hing like this though...

new scriptObject(Weapon_ICE) {
	power = 100;
	fire_speed = 100;
	misile_speed = 800;			
	level = 2;				
};


function playerShip::setWeapons(%this) {
	%this.playerMissile[0] = new t2dStaticSprite( : Weapon_ICE)
         {
            scenegraph = %this.scenegraph;
         };
}

the ":" tells it to copy all the properties from the object after it... The class field is for namespace linking only...
#3
07/27/2007 (11:53 am)
Whoa that is cool!
Where is the " : " operator in the documentation? I would like to read more about it and be able to refer people to it!
#4
07/27/2007 (1:22 pm)
@ Matthew Langley :
yeah . that works . tnx very much
#5
07/27/2007 (2:33 pm)
Pretty neat example... gonna give it a try, and maybe change some bits of code using the example... thx Matthew.