Game Development Community

Scripting prob ,CHAPTER 3 , 3d game programming all in one

by Bad_mofo · in Torque Game Engine · 12/19/2006 (12:21 am) · 2 replies

Hi , everybody , i just buyed this week the book mentionned above and right now im at the chapter tree , everything is going fine but im having problem to understand what ken want me to do ( im french by the way and the book is in english, so im not really sure if i understand well what he want)

so heres the code :

//============================================================================
//MoveShape.cs
//
//this module contains a function for moving a specified ShapeBase
//============================================================================

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


the script is running well in game : but he ask me to try to move the shape on several axis , but i think that whit that script that i can only move the X axis because of this: (%lx += %dist;).
and when im in the game the only command that work is this : moveshape($gh, 10); (example). so its only moving on the X axis. and when i try this : moveshape($gh, 10 20 30); its giving me a syntax error , so does that script is only abble to move the shape in only one direction???

secondly ived modified this line %lx += %dist; to this %lz += %dist; and it work on the z axis , but the main question is how do i can put several number to move the shape the way i want example(moveshape($gh, 10 20 30);) . anyway hope you guys understand my question.

thx for ur futur advice

#1
12/19/2006 (12:41 am)
Ived fund a way whit the sizeshape.cs example there its :

//===========================================================================
//sizeshape.cs
//
//this module contains a function for scaling a specified shape.
//===========================================================================

function SizeShape(%shape,%scale1,%scale2,%scale3)
//-----------------------------------------------------------------------------
// moves the %shape by %scale amount
//-----------------------------------------------------------------------------
{
echo("SizeShape: shape id: ", %shape);
echo("SizeShape: angle: ", %scale1 SPC %scale2 SPC %scale3);
%xfrm = %shape.getTransform();
%lx = getword(%xfrm, 0);
%ly = getword(%xfrm, 1);
%lz = getword(%xfrm, 2);
%lx = %scale1;
%ly = %scale2;
%lz = %scale3;
%shape.setScale(%scale1 SPC %scale2 SPC %scale3);
echo("SizeShape: done.");
}

im not a programmer so i hope the code make sens but its working in game , maybee if u have some tip to improve it just tell me!!!

so the problem was defining the axis whit proprety and add them in the function protocol!!! the genius in me pop out !!! :P

so theres the original version of it :

// ========================================================================
// sizeshape.cs
//
// This module contains a function for scaling a specified shape.
// ========================================================================


function SizeShape(%shape, %scale)
// ----------------------------------------------------
// moves the %shape by %scale amount
// ----------------------------------------------------
{
echo ("SizeShape: shape id: ", %shape);
echo ("SizeShape: angle: ", %scale);
%shape.setScale(%scale SPC %scale SPC %scale);
echo ("SizeShape: done.");
}
#2
12/19/2006 (8:51 am)
It looks like you need to add movement on other axes just like you have it on the x axis. I'm not fluent in TorqueScript at all, but I'll try and give you an idea. I've emboldened the bits I changed.

function Moveshape(%shape, %distx, %disty, %distz)
//------------------------------------------------------
// move the %shape by %distx,%disty,%distz amount
//------------------------------------------------------
{
echo("Moveshape: shape id: ", %shape);
echo("Moveshape: distance: ", %dist);
%xfrm = %shape.getTransform();
%lx = getWord(%xfrm,0);//get the current transform values
%ly = getWord(%xfrm,1);
%lz = getWord(%xfrm,2);
%lx += %distx;//adjust the x axis position
%ly += %disty;//adjust the x axis position
%lz += %distz;//adjust the x axis position

%shape.setTransform(%lx SPC %ly SPC %lz SPC "0 0 1 0");
echo("moveShape: done.");
}

There's probably a more efficient way to do this.