Tutorial Question (Player Movement)
by Bob · in Torque Game Builder · 03/02/2005 (4:38 pm) · 11 replies
Hi,
I am really new at Torque Script and I have a question.
I am following through the Tutorial and I am at the part where we start learning player movement.
I did everything the tutorial said but the player will not move.
Here is my code:
Any help would be great!
Bob
I am really new at Torque Script and I have a question.
I am following through the Tutorial and I am at the part where we start learning player movement.
I did everything the tutorial said but the player will not move.
Here is my code:
// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function setupT2DScene()
function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( - );
}
function playerUpStop()
{
$player.setLinearVelocityY( 0 );
}
{
// Create fxSceneGraph2D.
new fxSceneGraph2D(t2dSceneGraph);
// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dSceneGraph );
// Set Camera Position to be centered on (0,0) with
// view width/height of (100/80).
sceneWindow2D.setCurrentCameraPosition( "0 0 100 75" );
// ************************************************************************
//
datablock fxImageMapDatablock2D(playershipImageMap)
{
mode = full;
textureName = "~/client/images/playerShip";
};
$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
$player.setPosition("-35, 0");
$player.setSize( "14, 7" );
$player.setImageMap( playershipImageMap );
// set up the enemy
datablock fxImageMapDatablock2D(enemyship1ImageMap)
{
mode = full;
textureName = "~/client/images/enemyship1";
};
%enemy = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemy.setSize( "14, 7" );
%enemy.setPosition("40, 0");
%enemy.setImageMap( enemyship1ImageMap );
// move the enemy towards us.
%enemy.setLinearVelocityX(-20);
// Create a new action map
new ActionMap(playerMap);
// Bind keys to actions
playerMap.bindCmd(keyboard, "w", "playerUp();", "playerUpStop();");
playerMap.bindCmd(keyboard, "s", "playerDown();", "playerDownStop();");
playerMap.bindCmd(keyboard, "a", "playerLeft();", "playerLeftStop();");
playerMap.bindCmd(keyboard, "d", "playerRight();", "playerRightStop();");
playerMap.bindCmd(keyboard, "space", "playerFire();", "");
// Activate the action map.
player.push();Any help would be great!
Bob
About the author
#3
03/02/2005 (4:47 pm)
This might be over kill but here is mine$playerForce = 35;
// Start the player moving-up.
function playerUp()
{
// Fetch the players horizontal velocity.
%horz_velocity = getWord( $MAV.getLinearVelocity(), 0 );
$player.setLinearVelocity( %horz_velocity SPC -$playerForce );
}
// Stop the player moving-up.
function playerUpStop()
{
// Fetch the players velocity.
%velocity = $MAV.getLinearVelocity();
// Extract the component velocities.
%velX = getWord( %velocity, 0 );
$player.setLinearVelocity( %velX SPC 0 );
}
#4
Right now I am trying to just follow the basic tutorial.
Thanks for your help though :)
Bob
03/02/2005 (4:50 pm)
@AnthonyRight now I am trying to just follow the basic tutorial.
Thanks for your help though :)
Bob
#5
move the control functions OUT from the body of
function setupT2DScene()
like this
03/02/2005 (4:53 pm)
Check the console for errors press ~move the control functions OUT from the body of
function setupT2DScene()
like this
function playerUp(){
// Set the player moving up.
$player.setLinearVelocityY( - );
}
function playerUpStop(){
$player.setLinearVelocityY( 0 );
}
function setupT2DScene(){
#6
It is still not working.
I'm on OS X if that is any help.
Bob
03/02/2005 (5:02 pm)
Didn't see any errors.It is still not working.
I'm on OS X if that is any help.
Bob
#7
You first problem comes in right there at the top where you put "function playerUp()" You can't define a function "inside" another function. All functions have this format:
Take your playerUp() function and move it below the closing curley brace of the setupT2DScene() function. Should be something like this:
If you don't understand what I'm saying, you'll probably need to grab a book on C or C++ and get more of the basics down. Your second problem is the "-$10". It is a typo and should be "-10".
Matthew
03/02/2005 (5:08 pm)
Bob, you inserted you playerUpStop() function inside your setupT2DScene() function. You can't do that... This is from the code you posted:// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function setupT2DScene()
function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( - );
}
function playerUpStop()
{
$player.setLinearVelocityY( 0 );
}
{You first problem comes in right there at the top where you put "function playerUp()" You can't define a function "inside" another function. All functions have this format:
function your_function_name_here()
{
... you code here ...
}Take your playerUp() function and move it below the closing curley brace of the setupT2DScene() function. Should be something like this:
function setupT2DScene()
{
... existing code, and code you added as per the tutorial ...
}
// New functions added below.
// More player up
function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -10 );
}
// Stop moving player up.
function playerUpStop()
{
$player.setLinearVelocityY( 0 );
}If you don't understand what I'm saying, you'll probably need to grab a book on C or C++ and get more of the basics down. Your second problem is the "-$10". It is a typo and should be "-10".
Matthew
#8
and should be...
Need to remove the $ in -$10.
03/02/2005 (6:12 pm)
I had the same problem as well but it was nothing to do with nippley brackets. The PDF says...function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -[b]$[/b]10 );
}and should be...
function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -10 );
}Need to remove the $ in -$10.
#9
This has been corrected in the documentation and will be in the next update.
Sorry for the confusion this has caused.
- Melv.
03/03/2005 (2:18 am)
@luggage: Yes, that's what Jason said in the 2nd post in this thread. :)This has been corrected in the documentation and will be in the next update.
Sorry for the confusion this has caused.
- Melv.
#10
when you create a "function" you do this
function (put function name here)()
{
}
the "{" signify the beginning of defining that function and the "}" defines the end of the definition...
This tells the language what to use when you reference that function
an important thing to remember is a function should never be in another function
so
so this automatically will not work
reason why is
"function setupT2DScene()" get started... then you have put "function playerUp()" in it...
you need to make sure you start setupT2DScene and end it first before you declare another function... so the format would rather be this
that way they are defined as seperate functions
if you need any more help don't hesitate to ask
03/03/2005 (7:33 am)
@Bob:when you create a "function" you do this
function (put function name here)()
{
}
the "{" signify the beginning of defining that function and the "}" defines the end of the definition...
This tells the language what to use when you reference that function
an important thing to remember is a function should never be in another function
so
function setupT2DScene()
function playerUp()
{
// Set the player moving up.$player.setLinearVelocityY( - );
}so this automatically will not work
reason why is
"function setupT2DScene()" get started... then you have put "function playerUp()" in it...
you need to make sure you start setupT2DScene and end it first before you declare another function... so the format would rather be this
function setupT2DScene()
{
}
function playerUp()
{
}that way they are defined as seperate functions
if you need any more help don't hesitate to ask
Torque Owner Jason McIntosh
it might work. That's like taking money away from velocity. Just doesn't work! :)