naming a new object via for()
by rennie moffat · in Torque Game Builder · 10/25/2011 (8:54 am) · 9 replies
Hi there,
I am using a for() statement to create a group of objects classX. I want each object to have its own name, so that I can id it, and move it accordingly. So what I have done, but it does not work is this....
How, can I name my sldr, sldr0, then sldr1...... etc?
Thanks
I am using a for() statement to create a group of objects classX. I want each object to have its own name, so that I can id it, and move it accordingly. So what I have done, but it does not work is this....
%this.sldr @ "%count" = new t2dSceneObject(sldr @ "%count")
{
imageMap = "dPadPadImageMap";
frame = "0";
mUseSourceRect = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
PlatformTarget = "UNIVERSAL";
superclass = "dbClass";
Position = "0 0";
size = "64.000 64.000";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionPhysicsSend = "0";
CollisionPhysicsReceive = "0";
CollisionCallback = "1";
CollisionMaxIterations = "3";
CollisionPolyList = "-0.501 -0.363 0.516 -0.368 0.589 0.187 -0.584 0.192";
AlphaTestValue = "-1";
UsesPhysics = "1";
AutoMassInertia = "0";
Mass = "40.96";
Inertia = "27962";
mountID = "3";
_behavior0 = "";
};How, can I name my sldr, sldr0, then sldr1...... etc?
Thanks
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
10/25/2011 (1:00 pm)
You will not be able to name an object using dynamic variables. You have to use a literal name.
#3
However, this raises another question.
If I create a pool of objects, classA, groupX. Can I just forget about name and use those two fields to recognize the object and manipulate it? I am betting yes, but I have an affinity for naming.
Thanks.
ps. love the Halloween tribute (new profile pic). I hope thats what it is anyway. ::))(
10/25/2011 (1:16 pm)
so is the approach, using a count, to separate them and name them the only possible way?However, this raises another question.
If I create a pool of objects, classA, groupX. Can I just forget about name and use those two fields to recognize the object and manipulate it? I am betting yes, but I have an affinity for naming.
Thanks.
ps. love the Halloween tribute (new profile pic). I hope thats what it is anyway. ::))(
#4
It basically adds adds each of the items into an array that is tied to the object (%this) and adds a number onto each of the names as it creates them. Check your console after running and you should see them output by name.
10/25/2011 (5:01 pm)
Would something like this work Ren?for(%i = 0; %i < %this.dbCount; %i++)
{
%name = "sldr" @ %i;
%this.sldr[%i] = new t2dSceneObject(%name)
{
imageMap = "powerup_healthImageMap";
frame = "0";
mUseSourceRect = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
PlatformTarget = "UNIVERSAL";
superclass = "dbClass";
Position = "0 0";
size = "64.000 64.000";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionPhysicsSend = "0";
CollisionPhysicsReceive = "0";
CollisionCallback = "1";
CollisionMaxIterations = "3";
CollisionPolyList = "-0.501 -0.363 0.516 -0.368 0.589 0.187 -0.584 0.192";
AlphaTestValue = "-1";
UsesPhysics = "1";
AutoMassInertia = "0";
Mass = "40.96";
Inertia = "27962";
mountID = "3";
_behavior0 = "";
};
echo(%this.sldr[%i].getName());
}It basically adds adds each of the items into an array that is tied to the object (%this) and adds a number onto each of the names as it creates them. Check your console after running and you should see them output by name.
#5
A bunch of if statements?
if(%this.slidr[%i}.name $= "name011"
.....
:?
10/25/2011 (5:05 pm)
so if I wanted to call xObject (slidr[%i]).... how would I differentiate it from %this.slidr[%i]? Obviously, the name returned, but if I want %this.sldr[%i] to do this and that %this.sldr[%i] to do that, what would I do to call their name?A bunch of if statements?
if(%this.slidr[%i}.name $= "name011"
.....
:?
#6
10/25/2011 (5:08 pm)
I imagine you'd call them the same way did before? By name...sldr1.doSomething();
#7
so
%this.sldr[%i] is any sldr1, 2, 3, 4.... as much as I want. Since it was created as such... that name exists.
Oh sweet dude.
Thanks for the conformation.
By the way, how are tings? Have not been up in the TGB boards for a minute.
::))(( ps. your avatar still rocks.
:)(
10/25/2011 (5:11 pm)
oh reallY?!!so
%this.sldr[%i] is any sldr1, 2, 3, 4.... as much as I want. Since it was created as such... that name exists.
Oh sweet dude.
Thanks for the conformation.
By the way, how are tings? Have not been up in the TGB boards for a minute.
::))(( ps. your avatar still rocks.
:)(
#8
Things are going well here. I've been lurking the TGB forums; just not really posting often. I've been spending a lot of time in other engines because I was waiting to start a new TGB project until T2D was released and then GG went dark on it...
You?
10/25/2011 (5:15 pm)
Ya man, no problem. Thanks, I actually made that avatar in Lightwave; pretty proud of it!Things are going well here. I've been lurking the TGB forums; just not really posting often. I've been spending a lot of time in other engines because I was waiting to start a new TGB project until T2D was released and then GG went dark on it...
You?
#9
Other than that.....
Have you heard of a guy named Beeple? He makes a lot of art. One a day I believe in various mediums throughout the last 5 years. Currently, he is in After Effects I think. Anyhow, great 3D, lights, shape manipulation.
He directed a video called "Kill Your Co-Workers" by Flying Lotus. Look it up. Also, you can see his once a day's on his Facebook.
10/25/2011 (5:24 pm)
All my time in iTGB. building a sweet game right now. Temple Racer opened a lot of very coool doors for me. As such, all my time is spent learning and developing. Right now, I am hope to polish off my first solid demo of this title, by weeks end. If you want to beta test, send me your info!Other than that.....
Have you heard of a guy named Beeple? He makes a lot of art. One a day I believe in various mediums throughout the last 5 years. Currently, he is in After Effects I think. Anyhow, great 3D, lights, shape manipulation.
He directed a video called "Kill Your Co-Workers" by Flying Lotus. Look it up. Also, you can see his once a day's on his Facebook.
Torque Owner rennie moffat
Renman3000
for(%i = 0; %i < %this.dbCount; %i++) { %count = %count + 1; echo("formationSoldierSC:: %count" @ %count); if(%count == 1) { echo("formationSoldierSC:: %count == 1"); %this.sldr0 = new t2dSceneObject(sldr0) { imageMap = "dPadPadImageMap"; frame = "0"; mUseSourceRect = "0"; sourceRect = "0 0 0 0"; canSaveDynamicFields = "1"; PlatformTarget = "UNIVERSAL"; superclass = "dbClass"; Position = "0 0"; size = "64.000 64.000"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionCallback = "1"; CollisionMaxIterations = "3"; CollisionPolyList = "-0.501 -0.363 0.516 -0.368 0.589 0.187 -0.584 0.192"; AlphaTestValue = "-1"; UsesPhysics = "1"; AutoMassInertia = "0"; Mass = "40.96"; Inertia = "27962"; mountID = "3"; _behavior0 = ""; }; } else if(%count == 2) { %this.sldr1 = new t2dSceneObject(sldr1) { imageMap = "dPadPadImageMap"; frame = "0"; mUseSourceRect = "0"; sourceRect = "0 0 0 0"; canSaveDynamicFields = "1"; PlatformTarget = "UNIVERSAL"; superclass = "dbClass"; Position = "0 0"; size = "64.000 64.000"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionCallback = "1"; CollisionMaxIterations = "3"; CollisionPolyList = "-0.501 -0.363 0.516 -0.368 0.589 0.187 -0.584 0.192"; AlphaTestValue = "-1"; UsesPhysics = "1"; AutoMassInertia = "0"; Mass = "40.96"; Inertia = "27962"; mountID = "3"; _behavior0 = ""; }; } else if(%count == 3) { %this.sldr2 = new t2dSceneObject(sldr2) { imageMap = "dPadPadImageMap"; frame = "0"; mUseSourceRect = "0"; sourceRect = "0 0 0 0"; canSaveDynamicFields = "1"; PlatformTarget = "UNIVERSAL"; superclass = "dbClass"; Position = "0 0"; size = "64.000 64.000"; CollisionActiveSend = "1"; CollisionActiveReceive = "1"; CollisionPhysicsSend = "0"; CollisionPhysicsReceive = "0"; CollisionCallback = "1"; CollisionMaxIterations = "3"; CollisionPolyList = "-0.501 -0.363 0.516 -0.368 0.589 0.187 -0.584 0.192"; AlphaTestValue = "-1"; UsesPhysics = "1"; AutoMassInertia = "0"; Mass = "40.96"; Inertia = "27962"; mountID = "3"; _behavior0 = ""; }; } %this.sldr0.setPosition(%this.sldrPos0); %this.sldr1.setPosition(%this.sldrPos1); %this.sldr2.setPosition(%this.sldrPos2); } }