Game Development Community

Script error with functions

by Tim Saunders · in Torque Game Builder · 01/28/2006 (6:15 am) · 6 replies

Hello,

When trying the initial tutorial, I keep getting a script error for the following script:

function playerUp()
{
// Move the player up
$player.setLinearVelocityY( -10 );
}

Here is the error report - it doesn't seem to like my choice of function name, whatever I call it and even if I comment out the contents of the function:

Some error context, with ## on sides of error halt:

^// Functions to move the player
^function ##p##layerUp()
^{
^^// Move the player up
^^$player.setLinearVelocityY( -10 );
>> Error report complete.

Any ideas?

#1
01/28/2006 (6:21 am)
Ok I've figured it out now. I was putting the function definition in the wrong place.
#2
02/08/2006 (6:10 am)
My ship STILL doesn't move up, although the function's declared outside of the section most of the code until now has been placed. Could someone check this for me real quick?

Quote:

//---------------------------------------------------------------------------------------------
// Torque 2D.
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------
// setupT2DScene
// This function is the starting point for all game specific code.
//---------------------------------------------------------------------------------------------
function setupT2DScene()
{
// Create our scenegraph
new t2dSceneGraph(t2dScene);

// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dScene );

// Set the current camera position
sceneWindow2D.setCurrentCameraPosition("0 0 100 75");

// Add custom game code here...

datablock t2dImageMapDatablock(playershipImageMap)
{
imageMode = full;
imageName = "~/data/images/playerShip";
};
$player = new t2dStaticSprite() { scenegraph = t2dScene; };
$player.setPosition("-35 0");
$player.setSize( "14 7" );
$player.setImageMap( playershipImageMap );

// set up the enemy
datablock t2dImageMapDatablock(enemyship1ImageMap)
{
imageMode = full;
imageName = "~/data/images/enemyship1";
};
%enemy = new t2dStaticSprite() { scenegraph = t2dScene; };
%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.
playerMap.push();

$trigger = new t2dTrigger() { scenegraph = t2dScene; };
$trigger.setDebugOn(5);
$trigger.setPosition(10, 0);

$player = new t2dStaticSprite() { scenegraph = t2dScene; imageMap = ggLogoImageMap; };
$player.setPosition(-10, 0);
$player.setLinearVelocityX(5);
$player.setCollisionActive(true, true);
}

function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -10 );
}

function playerUpStop()
{
$player.setLinearVelocityY( 0 );
}

function t2dTrigger::onEnter(%this, %object)
{
echo("Enter:" @ %this SPC %object);
}

function t2dTrigger::onStay(%this, %object)
{
echo("Stay:" @ %this SPC %object);
}

function t2dTrigger::onLeave(%this, %object)
{
echo("Leave:" @ %this SPC %object);
}

#3
03/01/2006 (12:37 pm)
I see the problem, all of this should be pre build into the Game Builder and a button mapper that doesnt require all this code to be typed in.
#4
03/02/2006 (4:32 am)
@ Kev, but it isn't so we have to script

@Lorka

I'm a bit confused with your code but just at a first glance it seems your declaring $player twice, as two seperate static sprites? Which would mean your play movement functions may be influencing the wrong one?

I may be wrong, I only glanced and have to dash!
#5
03/02/2006 (7:37 am)
What Rob said seems to be right, you have 2 $player objects. Change these 4 lines:

$player = new t2dStaticSprite() { scenegraph = t2dScene; imageMap = ggLogoImageMap; };
$player.setPosition(-10, 0);
$player.setLinearVelocityX(5);
$player.setCollisionActive(true, true);

to:

$logo = new t2dStaticSprite() { scenegraph = t2dScene; imageMap = ggLogoImageMap; };
$logo.setPosition(-10, 0);
$logo.setLinearVelocityX(5);
$logo.setCollisionActive(true, true);

and the playerShip should move up. If you need to reference the ggLogo use the $logo variable now instead.
#6
03/03/2006 (2:14 pm)
Thanks Tim,

Your script helped me with a totally different problem (getting graphics on my screen). Now I can go back and find out what I was doing wrong:)

Ken