Very strange scripting/transform issue - Needs Help
by Nicolai Dutka · in Torque Game Engine Advanced · 04/08/2009 (5:44 pm) · 4 replies
I am running this:
makeGem(%amount,%xform);
echo("Should've made a gem at: "@ %xform);
And my echo statement is giving me the CORRECT numbers for the %xform, but my object is nowhere to be found... when I look for it in my editor, I see it there, but with WAAAY wrong coordinates... Here is my makeGem function:
makeGem(%amount,%xform);
echo("Should've made a gem at: "@ %xform);
And my echo statement is giving me the CORRECT numbers for the %xform, but my object is nowhere to be found... when I look for it in my editor, I see it there, but with WAAAY wrong coordinates... Here is my makeGem function:
function makeGem(%money,%xform)
{
%newGem = new Item() {
canSaveDynamicFields = "1";
Enabled = "1";
dataBlock = "gem";
rotate = "1";
rotate2 = "0";
scale = "0.5 0.5 0.5";
};
pickups.add(%newGem);
%newGem.money = %money;
if(%money==100) %newGem.setSkinName(gem2);
if(%money==1000) %newGem.setSkinName(gem3);
%newGem.setTransform(%xform);
echo("Set the new gem to xform: "@ %xform);
return %newGem;
}
#2
I have a staticShape with the following code:
Then I have this in my weapon projectile's onCollision:
Continued...
04/08/2009 (6:16 pm)
Ok it looks like I need to explain the whoooole scenario right now...I have a staticShape with the following code:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
datablock StaticShapeData( barrel )
{
category = "StaticShape";
shapeFile = "~/data/shapes/destructo/barrel.dts";
emap = true;
};
// Same as MakeWall, but with less options
function makeBarrel(%num, %key)
{
%newBarrel = new StaticShape() {
canSaveDynamicFields = "1";
Enabled = "1";
dataBlock = "barrel";
base = "barrel";
scale = "1.5 1.5 1.5";
};
%newBarrel.destructo = 1;
%newBarrel.money = 10;
if(%num==2)
{
%newBarrel.money = 100;
%newBarrel.setSkinName(barrel2);
}
if(%num==3)
{
%newBarrel.money = 1000;
%newBarrel.setSkinName(barrel3);
}
destructo.add(%newBarrel);
%t = $player.getTransform();
%x=getWord(%t,0);
%y=getWord(%t,1);
%z=getWord(%t,2)+ 0.5; //tweak for height
%a=getWord(%t,3);
%b=getWord(%t,4);
%c=getWord(%t,5);
%d=getWord(%t,6);
%t = %x SPC %y SPC %z SPC %a SPC %b SPC %c SPC %d;
%newBarrel.setTransform(%t);
%newBarrel.key = %key;
return %newBarrel;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Then I have this in my weapon projectile's onCollision:
//%otherObj = object getting shot
if( %otherObj.health > 0)
{
%otherObj.health -= 10;
if(%otherObj.health <= 0 )
{
$itemSpawnPos = %otherObj.getPosition();
%otherObj.schedule( 50, delete ); //schedule this or else the game may crash
}
}
if( %otherObj.destructo)
{
echo($player @" shot a destructo object");
//make explosion effect, sounds, and spawn pickups
// PLEASE!!!
if(%otherObj.money>0 && %otherObj.key==0)
{
echo("Destructo object location: "@ %otherObj.getTransform());
spawnMoney(%otherObj.money, %otherObj.getTransform());
}
if(%otherObj.key)
{
makeKey(%otherObj.key,%otherObj.getTransform());
}
%otherObj.schedule( 50, delete );
}Continued...
#3
Which in turn leads to the makeGem code I wrote above:
Now... if you follow the logic, you end up with the following echo statement results:
However, if you look in the 'destructo' SimGroup, the objects are all there, but with the following positions:
781.369 1577.91 50.0117
279.456 -1277.32 2022.16
245.364 1153.91 59.4073
-570.638 386.445 -846.426
If the numbers weren't so completely random... I might have some ideas... as it were... this is completely baffling...
04/08/2009 (6:17 pm)
So now we have a destructo Barrel that spawns money when shot:function spawnMoney(%amount,%xform)
{
%num = getRandom(1,40);
if(%num==40)
{
echo("Got a perfect 40, do something special");
}
else
{
makeGem(%amount,%xform);
echo("Should've made a gem at: "@ %xform);
}
}Which in turn leads to the makeGem code I wrote above:
datablock ItemData(gem)
{
// Basic Item properties
shapeFile = "~/data/shapes/pickups/gem.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
// Dynamic properties defined by the scripts
pickUpName = "Gem";
};
function makeGem(%money,%xform)
{
%newGem = new Item() {
canSaveDynamicFields = "1";
Enabled = "1";
dataBlock = "gem";
rotate = "1";
rotate2 = "0";
scale = "0.5 0.5 0.5";
};
pickups.add(%newGem);
%newGem.money = %money;
if(%money==100) %newGem.setSkinName(gem2);
if(%money==1000) %newGem.setSkinName(gem3);
%newGem.setTransform(%xform);
echo("Set the new gem to xform: "@ %xform);
return %newGem.getTransform();
}
function gem::onCollision(%thisDB, %thisObj, %otherObj, %speed, %vec)
{
if(%otherObj==$player)
{
$player.money+=%thisObj.money;
//play pickup sound/effect
%thisObj.schedule( 10, delete );
}
}Now... if you follow the logic, you end up with the following echo statement results:
==>makeBarrel(); ==>makeBarrel(); ==>makeBarrel(); ==>makeBarrel(); ==>makeBarrel(); 2272 shot a destructo object Destructo object location: 589.427 1000.67 30.8561 0 0 1 3.67398 Set the new gem to xform: 589.427 1000.67 30.8561 0 0 1 3.67398 Should've made a gem at: 589.427 1000.67 30.8561 0 0 1 3.67398 2272 shot a destructo object Destructo object location: 589.427 1000.67 30.8561 0 0 1 3.67398 Set the new gem to xform: 589.427 1000.67 30.8561 0 0 1 3.67398 Should've made a gem at: 589.427 1000.67 30.8561 0 0 1 3.67398 2272 shot a destructo object Destructo object location: 589.427 1000.67 30.8561 0 0 1 3.67398 Set the new gem to xform: 589.427 1000.67 30.8561 0 0 1 3.67398 Should've made a gem at: 589.427 1000.67 30.8561 0 0 1 3.67398 2272 shot a destructo object Destructo object location: 589.427 1000.67 30.8561 0 0 1 3.67398 Set the new gem to xform: 589.427 1000.67 30.8561 0 0 1 3.67398 Should've made a gem at: 589.427 1000.67 30.8561 0 0 1 3.67398 2272 shot a destructo object Destructo object location: 592.997 1003.8 30.1817 0 0 1 3.84358 Set the new gem to xform: 592.997 1003.8 30.1817 0 0 1 3.84358 Should've made a gem at: 592.997 1003.8 30.1817 0 0 1 3.84358
However, if you look in the 'destructo' SimGroup, the objects are all there, but with the following positions:
781.369 1577.91 50.0117
279.456 -1277.32 2022.16
245.364 1153.91 59.4073
-570.638 386.445 -846.426
If the numbers weren't so completely random... I might have some ideas... as it were... this is completely baffling...
#4
04/09/2009 (1:44 pm)
The crazy thing is, I wrote this code for a different game using TGEA 1.8.1 and the code WORKS in that game... I simply copy/pasted all the code to my new project and now getting this CRAZY issue...
Torque 3D Owner Nicolai Dutka