MoveShape.cs - Clearly I am doing it wrong...
by Ian Smithers · in Torque Game Engine · 02/27/2005 (10:17 am) · 10 replies
Function MoveShape(%shape,%dist)
//
// Moves the %shape by %dist amount
//
{
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); // get the current transform values
%ly = getword(%xfrm,1);
%lz = getword(%xfrm,2);
%lx += %dist;
%shape.setTransform(%lx SPC %ly SPC %lz SPC "0 0 1 0");
}
Ok so at the end of the MoveShape.cs program Ken says to mess around with it and trying moving the shape along several axis at once and changing the distance.
Right.
Well, I thought that the bold text above was the variable I had to change in order to move it along a different axis. But I have since been proven wrong, because it doesn't work. So what am I missing here? Above is the MoveShape function, and (to my untrained eye) it looks like when I type "MoveShape($ian,5);" into the console, it will move the shape by 5 along the x axis and indeed it does. Ignore the $ian, I was just playing about.
So, in my untrained mind, I think, lets change %lx to %lz, and this will move the shape along the z axis. Yet it doesn't. So obviously I am missing something.
Anyone care to shower me with their wisdom? :D
Cheers!
Ian
//
// Moves the %shape by %dist amount
//
{
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); // get the current transform values
%ly = getword(%xfrm,1);
%lz = getword(%xfrm,2);
%lx += %dist;
%shape.setTransform(%lx SPC %ly SPC %lz SPC "0 0 1 0");
}
Ok so at the end of the MoveShape.cs program Ken says to mess around with it and trying moving the shape along several axis at once and changing the distance.
Right.
Well, I thought that the bold text above was the variable I had to change in order to move it along a different axis. But I have since been proven wrong, because it doesn't work. So what am I missing here? Above is the MoveShape function, and (to my untrained eye) it looks like when I type "MoveShape($ian,5);" into the console, it will move the shape by 5 along the x axis and indeed it does. Ignore the $ian, I was just playing about.
So, in my untrained mind, I think, lets change %lx to %lz, and this will move the shape along the z axis. Yet it doesn't. So obviously I am missing something.
Anyone care to shower me with their wisdom? :D
Cheers!
Ian
#2
I wanted to change:
to
to move the shape along the z axis, but it still goes along the x. I think I have completely misread the code or soemthing. :(
Ian
02/27/2005 (10:23 am)
Hehe, ah ok. Thanks. ;)I wanted to change:
%lx += %dist;
to
%lz += %dist;
to move the shape along the z axis, but it still goes along the x. I think I have completely misread the code or soemthing. :(
Ian
#3
All this time I had saved my program to the CH2 folder, and had been adjusting it, and then checking the results with the program in the CH3 folder.
The good news is that I understood the code correctly and now that I am running the right program, it works as expected.
Gah!
Ian
P.S. I have a new question now, which is why the {} of the datablock area and the insert shape function, require a ";" on the closed bracket, as below:
02/27/2005 (10:47 am)
Wow, I'm a retard. :(All this time I had saved my program to the CH2 folder, and had been adjusting it, and then checking the results with the program in the CH3 folder.
The good news is that I understood the code correctly and now that I am running the right program, it works as expected.
Gah!
Ian
P.S. I have a new question now, which is why the {} of the datablock area and the insert shape function, require a ";" on the closed bracket, as below:
{
// Basic item properties
shapeFile = "~/data/shapes/items/heart.dts";
mass = 1; // we give the shape mass and
friction = 1; // friction to stop the item from sliding down hills
[b]};[/b]
#4
02/27/2005 (12:38 pm)
Because it's at the end of a statement.
#5
Why do all the other "}" not require a semicolon?
Ian
02/27/2005 (12:47 pm)
Ok I guess I am being slow but how is the "}" is at an end of a statement? Why do all the other "}" not require a semicolon?
Ian
#6
02/27/2005 (12:52 pm)
Actually, TGEScript overrides the use of {...} which normally define execution blocks to be "datablock parameter blocks" in this one specific case. AFAIK you'll only need to put the ; at the end of a {...} block when you are defining runtime parameters to the TGEScript "new" command.
#7
Cos I am not sure exactly what that is, for I am just a beginner as it were. :)
Ian
02/27/2005 (1:03 pm)
Just so I am not going crazy, can you confirm there is a runtime parameter in this:{
// Basic item properties
shapeFile = "~/data/shapes/items/heart.dts";
mass = 1; // we give the shape mass
friction = 1; // and friction to stop it sliding
};Cos I am not sure exactly what that is, for I am just a beginner as it were. :)
Ian
#8
What's important to realize is that your {...} block is only appropriate (with the trailing semi-colon) because of the fact of the line I added. All 3 of the values that are set within the {...} block are part of the parameters given to the new command.
Going back to what Bryan said, the code I have above is all one statement (in this case), and therefore needs a ; at the end.
02/27/2005 (2:04 pm)
You are slightly quoting the code out of context, so it's difficult to be sure. Assuming that the code I think is just above that block, it will look something like this:[b]%newObject = new SomeObjectType()[/b]
{
// Basic item properties
shapeFile = "~/data/shapes/items/heart.dts";
mass = 1; // we give the shape mass
friction = 1; // and friction to stop it sliding
};What's important to realize is that your {...} block is only appropriate (with the trailing semi-colon) because of the fact of the line I added. All 3 of the values that are set within the {...} block are part of the parameters given to the new command.
Going back to what Bryan said, the code I have above is all one statement (in this case), and therefore needs a ; at the end.
#9
Yeah the full code (doh) is like so:
And there is a similar section beneath with a function laid out in the same format.
Ok cool, thanks! :)
Ian
02/27/2005 (2:36 pm)
Oooooooooooooooh. :D Ok cool, thanks.Yeah the full code (doh) is like so:
datablock ItemData(TestShape)
//
// Definition of the shape object.
//
{
// Basic item properties
shapeFile = "~/data/shapes/items/heart.dts";
mass = 1; // we give the shape mass
friction = 1; // and friction to stop it sliding
};And there is a similar section beneath with a function laid out in the same format.
Ok cool, thanks! :)
Ian
#10
02/27/2005 (2:40 pm)
Yes, the specific syntax (semi-colon at end) applies to datablock definitions as well!
Torque Owner Stefan Lundmark
Function MoveShape(%shape,%dist) { %xfrm = %shape.getTransform(); %lx = getword(%xfrm,0); // get the current transform values %ly = getword(%xfrm,1); %lz = getword(%xfrm,2); %lx += %dist; // <- %shape.setTransform(%lx SPC %ly SPC %lz SPC "0 0 1 0"); }Is far easier to read :) Sorry I can't help you with your question though. :/