Game Development Community

Moveshape problem

by Keith H · in Technical Issues · 02/24/2008 (3:51 pm) · 4 replies

//==============================================================================
// moveshape.cs
//
// This module contains a function for moving a specified shape.
//==============================================================================

function MoveShape(%shape, %dist)
//------------------------------------------------------------------------------
// MOVE THE %SHAPE BY %DIST AMOUNT
//------------------------------------------------------------------------------
{
echo("MoveShape: shape id: ", %shape);
echo("MoveShape: distance: ", %dist);
%xfrm = %shape.getTransform();
%1x = getword(%xfrm,0); //get the current transform values
%1y = getword(%xfrm,1);
%1z = getword(%xfrm,2);
%1x += %dist;
%shape.setTransform(%1x SPC %1y SPC %1z SPC "0 0 1 0");
echo ("MoveShape: done.");
}

Torque says there is a syntax error in line 15, but I copied straight from my source and it still says there is an error. What could I be missing?

#1
02/24/2008 (4:06 pm)
Try this (The problem is in bold).
// ========================================================================
//  moveshape.cs
//
//  This module contains a function for moving a specified shape.
// ========================================================================

function MoveShape(%shape, %dist)
// ----------------------------------------------------
//     moves the %shape by %dist amount
// ----------------------------------------------------
{
	 echo ("MoveShape: shape id: ", %shape);
	 echo ("MoveShape: distance: ", %dist);
   %xfrm = %shape.getTransform();
   [b]%lx[/b]= getword(%xfrm,0); // get the current transform values
   [b]%ly[/b] = getword(%xfrm,1);
   [b]%lz[/b] = getword(%xfrm,2);
   [b]%lx[/b] += %dist;          // adjust the x axis position
   %shape.setTransform([b]%lx[/b] SPC [b]%ly[/b] SPC [b]%lz[/b] SPC "0 0 1 0");
	 echo ("MoveShape: done.");
}

The problem is that a number can't be a variable.
#2
02/29/2008 (5:13 pm)
Should it be lx instead of 1x. I can't really see a difference with what was done.
#3
02/29/2008 (10:56 pm)
It's kinda hard to tell, but the difference is that it's an "L" instead of a 1. So lx would be correct because numbers can't be variables. If you got the source code from "3D Game Programming All In One," there is a CD that comes with it and it contains all of the source code.
#4
03/01/2008 (6:56 am)
Ok, thank you.