StaticShape: Damage: onDamage: playThread
by Rex · in Torque Game Engine · 10/09/2005 (2:53 pm) · 7 replies
Hi ho all scriptors out there...I've gotten to scripting some objects for a project and have noticed some weird behavior I can't explain and need some help. It is a staticShape object that has 3 animations to be played randomly when the object is hit with a projectileClass object.
I gave the object a function myObject::damage method.
I gave the object a function myObject::onDamage method that appends a random number generated on the end of the sequence name string in a %obj.playThread() statement.
I also added both a echo and MessageAll statement too, and they work perfectly in synce, each having the same results; here's where the weirdness starts to appear.
...with a simple echo statement, I get two lines of output on the console and chatHUD...odd.
...and when I add my random number to the PRINT statements, I get two different outputs...!!!
Can anyone help me understand what is going on and why the routine seems to be run twice??? and why there might be two separate variables stuffed into the strings??
Thanks, I'm an artist, trying to script my objects to life....:). Any help is appreciated.
Rex
I gave the object a function myObject::damage method.
I gave the object a function myObject::onDamage method that appends a random number generated on the end of the sequence name string in a %obj.playThread() statement.
I also added both a echo and MessageAll statement too, and they work perfectly in synce, each having the same results; here's where the weirdness starts to appear.
...with a simple echo statement, I get two lines of output on the console and chatHUD...odd.
...and when I add my random number to the PRINT statements, I get two different outputs...!!!
Can anyone help me understand what is going on and why the routine seems to be run twice??? and why there might be two separate variables stuffed into the strings??
Thanks, I'm an artist, trying to script my objects to life....:). Any help is appreciated.
Rex
About the author
Rex does all his 3D graphics through BrokeAssGames and is currently working on DSQTweaker, Ecstasy Motion, and other interesting projects yet to be revealed. Just ask him about anything DTS/DSQ related, he's happy to help.
#2
Well, definitely needs the WeatherVane::damage method, nothing happens without it....
Now, when I put anything other than "1", in %obj.applyDamage, the console starts issuing warning about not finding the object and the object not being a correct class of object. This looks nearly the same code from the second vol of K. Finney's book, I'm just trying to understand the 'flow' of code to make this weaving comprehendable.

This image shows the output to the console, I went back and placed an echo right after the call to %col.damage....the echo from the CrossbowProjectile::onCollision block is nessled neatly between the first and second pass thru the routine....please anyone with scripting knowledge, please hep me here, make sense of TorqueScript....
Rex
10/09/2005 (7:10 pm)
Here is what I've got going and perhaps this Thread could help some others trying to do some simple activation of their art assets:datablock StaticShapeData(WeatherVane)
{
category = "Decos";
shapeFile = "~/data/shapes/Deadwater/windmech.dts";
maxDamage = 10000;//trying to get damage for the object-oldvalue=0.5
destroyedLevel = 0.5;
disabledLevel = 0.25;
renderWhenDestroyed = true;
// debrisShapeName = "~/data/shapes/glass/shard.dts"; // Add shape
// debris = GlassTubeDebris;
decoName = "a weathervane";
};
function WeatherVane::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
echo("\c2WeatherVane-damage has been called");
%obj.applyDamage("1");
}
function WeatherVane::onDamage(%this, %obj, %delta)
{
echo("\c2WeatherVane-onDamage has been called");
%ranNum = getRandom(0,2);
%obj.playThread(0,"spin"@%ranNum);
echo("\c2WeatherVane-sequence SPIN"@%ranNum@"\c2 has just been run");
MessageAll('MsgAdminForce',"\c2WeatherVane-sequence SPIN"@%ranNum@"\c2 has just been run");
}
function WeatherVane::onAdd(%this,%obj)
{
echo("a weatherVane has been added");
%obj.playThread(1,"Cspin0");
echo("weatherVane should be spinning now...");
}...this what I've got going, so far, and I put an echo with the shapeBase.cs script's ::damage and I can't see where what is happening?? Do I need my WeatherVane::damage function? or does the parent Class take over?Well, definitely needs the WeatherVane::damage method, nothing happens without it....
Now, when I put anything other than "1", in %obj.applyDamage, the console starts issuing warning about not finding the object and the object not being a correct class of object. This looks nearly the same code from the second vol of K. Finney's book, I'm just trying to understand the 'flow' of code to make this weaving comprehendable.

This image shows the output to the console, I went back and placed an echo right after the call to %col.damage....the echo from the CrossbowProjectile::onCollision block is nessled neatly between the first and second pass thru the routine....please anyone with scripting knowledge, please hep me here, make sense of TorqueScript....
Rex
#3
I cleared up some of the issues I'm having with working with damage and using %obj.playThread. Before, I was having my continous rotations being applied to the vanes of the windmech, and my damage seqeunces also; albeit on different Threads.
What would happen is that the damage sequence would play, but it would stop playing the cyclic one, this I attributed to the Node attempting to be driven by two different sequences with the same priority. So I decided to adjust my objects workings.
I thought it might be better to separate my actions into two separate parts of the object andthreads; so I decided to have the cyclic animation playing on the vanes[to help simulate the cloud cover's vector as they stream by overhead,;)], while making the reaction to the damage rotate the entire weatherVane structure. To further help things along, I made this pivot sequence .dsq file a Blend type.
Things work much better now; the windmech's 'vane's' spin continously[always], and now,when the object is struck with a projectile; the entire 'head' spins as per the sequence length, and returns to it's 'root' position. What still is happening is that my ::damage calling the ::onDamage routine of applying damage twice and playing the Thread, once.
10/11/2005 (8:09 am)
More observations:I cleared up some of the issues I'm having with working with damage and using %obj.playThread. Before, I was having my continous rotations being applied to the vanes of the windmech, and my damage seqeunces also; albeit on different Threads.
What would happen is that the damage sequence would play, but it would stop playing the cyclic one, this I attributed to the Node attempting to be driven by two different sequences with the same priority. So I decided to adjust my objects workings.
I thought it might be better to separate my actions into two separate parts of the object andthreads; so I decided to have the cyclic animation playing on the vanes[to help simulate the cloud cover's vector as they stream by overhead,;)], while making the reaction to the damage rotate the entire weatherVane structure. To further help things along, I made this pivot sequence .dsq file a Blend type.
Things work much better now; the windmech's 'vane's' spin continously[always], and now,when the object is struck with a projectile; the entire 'head' spins as per the sequence length, and returns to it's 'root' position. What still is happening is that my ::damage calling the ::onDamage routine of applying damage twice and playing the Thread, once.
#4
10/11/2005 (9:50 am)
Did you modify the crossbow.cs script? i cant be sure without looking at all of your code but the problem may lie with the accompanying explosion and radiusdamage function which is called when the projectile collides with something. i cant look at the script right now, but it may be that the damage is being applied twice, once for when the object collides with the projectile, and then again when radiusdamage is called. if this is the case, you may only see the second playthread being played because its called a split second after the first playthread.
#5
Thanks again, Sean for looking and helping; I'd love to get this figured out, so it will make extrapolation that much easier...already works pretty good. First think I'll do is get rid of radius damage and see what appears.
More Observations:
Commenting out the radius damage from the crossbow projectile did indeed get rid of the second pass thru the routine!
Now, here's more and this may be part of the NLA system and the playThread or my random number generation scheme and use:
The first return of any randomNumber generation that gets appended onto the "spin" sequence name works great, but any repeat of the same number[very few to actually return], does NOT run the sequence and this bad value return continues until a new random number is generated and appended to the sring?!? This happened without exception: I'd hit the target, get my single output to both console & chatHUD, insert a PRINT "break" and try another shot. If the same number was generated, the playThread doesn't happen but I get console/HUD output, and this actually continues until a new number is inserted. I watched the value 1 for example, come up about 3 times in a row and every succeeding returned 1 got no sequence to play.
Rex
10/11/2005 (10:28 am)
Thanks, Sean, that's probably it[haven't touched crossbow.cs at all], as I haven't inserted any of our design weapons into this build with the LightingPack. From your explanation; it does seem that this is what is perhaps happening? Can you suggest a way to have this not, happen[the two times thru the routine]? Is this something delt with inside each individual weapons projectile? or in the deco object itself?? I'm an artist primarily and find getting the correct command in the correct locations a bit tricky,;). The weapon's radius damage hasn't been touched by me, and I've had troubles with it before[radiusDamage], getting damage to the player shape with my dynamite type 'thrown' projectile....Thanks again, Sean for looking and helping; I'd love to get this figured out, so it will make extrapolation that much easier...already works pretty good. First think I'll do is get rid of radius damage and see what appears.
More Observations:
Commenting out the radius damage from the crossbow projectile did indeed get rid of the second pass thru the routine!
Now, here's more and this may be part of the NLA system and the playThread or my random number generation scheme and use:
The first return of any randomNumber generation that gets appended onto the "spin" sequence name works great, but any repeat of the same number[very few to actually return], does NOT run the sequence and this bad value return continues until a new random number is generated and appended to the sring?!? This happened without exception: I'd hit the target, get my single output to both console & chatHUD, insert a PRINT "break" and try another shot. If the same number was generated, the playThread doesn't happen but I get console/HUD output, and this actually continues until a new number is inserted. I watched the value 1 for example, come up about 3 times in a row and every succeeding returned 1 got no sequence to play.
Rex
#6
%obj.playThread(0,"spin"@%ranNum);
dont worry about calling stopthread() if an animation isnt playing.
10/11/2005 (11:13 am)
Rex i think you may need to call stopthread before you can play it again. if you play a different thread the first will stop automatically. try placing a call to stopthread(0) right before:%obj.playThread(0,"spin"@%ranNum);
dont worry about calling stopthread() if an animation isnt playing.
#7
Thanks Sean, if anyone has any other ideas on making the Threads play one after another, please let me know. To me; this seems pretty basic functionality......having animation sequence played on cue?!?
10/11/2005 (1:28 pm)
Ah, back from lunch; and tried the %obj.stopThread on the appropriate Thread....and it still 'balks' when the same number is generated a succeeding time.....yep, just had 3 value=1 come up and the Thread doesn't play...?? And now 3 value=0 and same issue; the Thread does not run, until a new number is stufed into the slot. Dang, probably needs an if(!Object(blah, blah)) to work, not something I'm very good at.Thanks Sean, if anyone has any other ideas on making the Threads play one after another, please let me know. To me; this seems pretty basic functionality......having animation sequence played on cue?!?
Torque Owner Dracola
the ::damage method gets called from something that would look like this
%this.damage(0, %this.getPosition(), 10000, %damageType);
%this being your player
if that is getting called twice so would ::ondamage so search for .damage(
and see where it could be getting run twice maybe put an echo infront of all the things that could be calling it.