Game Development Community

CH3 - Rotation, Scaling, Animation and Audio examples problem

by Matt Troup · in Torque Game Engine · 06/15/2005 (3:31 am) · 2 replies

All previous examples have worked fine from "Hello World" to "Programmed Movement" (which is in the same chapter as the following).

I've run into problems with the remaining examples in chapter 3.

I'm getting similar problems for each in regards to loading.

For isntance, in the animation example after I type in the console

exec("CH3/animshape.c");

I get the return:

Ch3/animshape.c (0): preload failed for TestShape: ShapeBaseData Couldn't load shape "~data/shapes/items/heart.dts"

If it helps any, on a couple of the errors it says "string always evaluates to 0"

Here's my code for the anim example. Maybe you could help me out to see if you get the same report on your system? Thanks for the help. I apologize I've forgotten how to type in paragraphs - too much coding for one night.

//====================================================
// animshape.c
//
// This module contains the definition of a test shape
// which uses a model of a stylized heart
// It also contains functions for placing the test shape
// in the game world and then animating the shape using
// a recurring scheduled function call
//====================================================

datablock ItemData(TestShape)
//----------------------------------------------------
// Definition of the shape object
//----------------------------------------------------

{
// Basic Item Properties
shapeFile = "~data/shapes/items/heart.dts";
mass = 1; // give the shape mass and friction
friction = 1; // to stop it from sliding down hills

};

function InsertTestShape()
//----------------------------------------------------
// Instantiates the test shape, then inserts it
// into the game world roughly in fron of
// the player's default spawn location
//----------------------------------------------------

{
// An example function which creates a new TestShape object
%shape = new Item()

{
datablock = TestShape;
rotation = "0 0 1 0"; // initialize the values
// to something meaningful
};
MissionCleanup.add(%shape);

//Player setup
%shape.setTransform("-90 -2 20 0 0 1 0");
echo("Inserting Shape " @ %shape);
return %shape;
}

function AnimShape(%shape, %dist, %angle, %scale)
//-----------------------------------------------------
// moves the %shape by %dist amoutn , and then
// schedules itself to be called again in 1/5
// of a second
//-----------------------------------------------------

{
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); // first, get the current transform values
%ly = getword(%xfrm,1);
%lz = getword(%xfrm,2);
%rx = getword(%xfrm,3);
%ry = getword(%xfrm,4);
%rz = getword(%xfrm,5);
%lx += dist; // set the new x possition
%angle += 1.0;
%rd = %angle; // set the rotation angle

if ($grow)

{
if (%scale < 5.0) // hasn't gotten too big
%scale += 0.3; // make it bigger
else
$grow = false; //it it's too big, then don't make it grow
}
else // if it's shrinking

{
if (%scale > 3.0) // and isn't too small
%scale -= 0.3; // then make it smaller
else
$grow = true; // if it's too small, don't let it grow smaller
}

%shape.setScale(%scale SPC %scale SPC %scale);
%shape.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %rd);
schedule(200.0,AnimShape, %shape, %dist, %angle, %scale);
}

function DoAnimTest()
//----------------------------------------------------
// a function to tie together the instantiation and the
// movement in one easy to type function call
//----------------------------------------------------

{
%as = InsertTestShape();
$grow = true;
AnimShape(%as,0.2, -1, -2);
}

#1
07/07/2005 (11:08 am)
In the item datablock you're missing the / after the ~ in the bolded section below.

// Basic Item Properties
shapeFile = "~data/shapes/items/heart.dts";
mass = 1; // give the shape mass and friction
friction = 1; // to stop it from sliding down hills
#2
07/07/2005 (11:15 am)
%lx += dist; // set the new x possition

should be

%lx += %dist; // set the new x possition

I beleive