Game Development Community

Please can someone check this code

by arteria3d · in Torque Game Engine · 12/04/2004 (2:29 pm) · 6 replies

Hi, i have written the below simple code that i expect to move a shape up and down on a loop, changing when certain values are met. I am echoing the amount back to make sure the value is changing and it is - but the object is staying stationery on the screen. Could someone kindly take a look and see what the problem may be. I am learning C Script as an ongoing project with the Ken Finney Book - all help would be apreaciated.

Thanks

Steve

THe CODE is:




$alter = 0;


datablock itemdata(testshape)

{
shapefile ="~/data/shapes/items/heart.dts";
mass = 1;
friction = 1;

};

function inserttestshape()
{
$shape = new item(){
datablock = testshape;
rotation = "0 0 1 0";
};



missioncleanup.add($shape);

$shape.setTransform("-90 -2 20 0 0 1 0");
return $shape;
}






function animate($shape,$cx)
{



if ($alter == 0)
$cx +=1;

if ($alter == 1)
$cx -=1;



if ($cx >= 50 && $alter == 0)
$alter = 1;
if ($cx <=0 && $alter == 1)
$alter = 0;

$shape.setTransform("-90 -2 $cx 0 0 1 0");






echo($cx);
schedule(200,0,animate,$shape,$cx);

}



function doanim()

{
$as = inserttestshape(testshape);

animate($as,40);

}

About the author

Owner of uk based Ltd company ArteriaMediaLtd. with a trading name of Arteria3d Website;arteria3d.com


#1
12/04/2004 (2:32 pm)
$shape.setTransform("-90 -2 $cx 0 0 1 0");

looks wrong to me.. try

$shape.setTransform("-90 -2" SPC $cx SPC "0 0 1 0");
#2
12/04/2004 (4:46 pm)
Thanks - that was the problem. Could u explain to me why that actually works, cos ur context looks different to the one in Ken FInney book - but urs works!!!

Steve
#3
12/04/2004 (4:50 pm)
Stevie,

I do not have Ken's book, could you show me his syntax.

I assume it is something like

$shape.setTransform("-90 -2 " @ $cx @ " 0 0 1 0");

which does the same as

$shape.setTransform("-90 -2" SPC $cx SPC "0 0 1 0");

the only diff is SPC puts a space before the variable (in this case $cx) and @ just concats the value without a sapce, hence the space between 2 and " as well as between " and 0

might be worth while to read some of the scripting documentation listed on the site.
-Ron
#4
12/04/2004 (4:52 pm)
You were setting Z to "$cx" not the value of $cx.
#5
12/04/2004 (4:52 pm)
Thankyou.

i notice also even though i added mass as 0, thatthe object moveed choppy up and down, cos it was obviously fighting its own gravity.

When an object is added in the mission editor - it stays where it is put, eve if this is in the air.... is there a way of altering the datablock object so it doesnt have gravity, and thus moves smoothly where i tell it to go, without the pull of gravity.

Cheers

Steve
#6
12/04/2004 (4:53 pm)
Westy - i got yer - and understand what ur saying. Thanks - after weeks of trying to get my head around datablocks etc i think i am almost there

Cheers

Steve