Game Development Community

Issue with shooter demo in 1.2

by Hokuto · in Torque Game Builder · 07/14/2005 (2:26 pm) · 16 replies

Hi there...
I was messing around with some test using the shooter demo...
but anyway...
what happens now is that the only control key that works is the
W = move up
any of the other 3 keys doesn't work with the latest T2D 1.2

What I did, to make sure it wasn't just me messing things up..
I copied the client.cs file from the shooter tutorial I did some time ago
from the old version of T2D and pasted/overwrite it into the new T2D 1.2

guess what, the player ship only moves up!

//CODE FOR MOVING-----------------------
function playerUP()
{
//set the player moving up
$player.setLinearVelocityY( -20);
}

function playerUPStop()
{
//stop player from moving up IF YOU ARE MOVING UP!
if ( $player.getLinearVelocityY() < 0 )
$player.setLinearVelocityY( 0 );
}



function playerDown()
{
// Set the player moving down.
$player.setLinearVelocityY( 20 );
}
function playerDownStop()
{
// If we're moving down then nullify any downward movement.
if ( $player.getLinearVelocityY() > 0 )
$player.setLinearVelocityY( 0 );
}




function playerLeft()
{
// Set the player moving left.
$player.setLinearVelocityX( -20 );
}
function playerLeftStop()
{
// If we're moving left then nullify any leftward movement.
if ( $player.getLinearVelocityX() < 0 )
$player.setLinearVelocityX( 0 );
}




function playerRight()
{
// Set the player moving right.
$player.setLinearVelocityX( 20 );
}
function playerRightStop()
{
// If we're moving right then nullify any rightward movement.
if ( $player.getLinearVelocityX() > 0 )
$player.setLinearVelocityX( 0 );
}

// CODE FOR MOVING-----------------------


The console says:
(0) : Unable to find function playerRight
(0) : Unable to find function playerRightStop
(0) : Unable to find function playerLeft
etc... including playerFire


but why does Up work... and not the others...
strange....

#1
07/14/2005 (4:19 pm)
Whats your ActionMap code look like?
#2
07/14/2005 (4:28 pm)
// 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();", "");

//Active the action map
playerMap.push();



I'm sure the code is just as in the original basic tutorial.. it does work with the old T2D sdk.....
but the same code in the new T2D 1.2 only moves the ship up !??!!?
:)
Thanks for looking into it...
#3
07/14/2005 (5:06 pm)
Most likely, there's a syntax error that prevented the other functions from being compiled. Check the timestamp for client.cs.dso; if it's earlier than the timestamp for client.cs, you'll know there's a problem. You can delete the dso file and restart the engine. If there's a syntax error, either it will be reported in the console, or the engine will refuse to run at all.
#4
07/14/2005 (7:32 pm)
Could be a weird keyboard related error as well... I noticed it in one of my little tech demos on a machine with a keyboard with an f-lock button. For some reason if the F-Lock wasn't enabled, I'd have all sorts of weird control bugs, even though my action-map used NO function keys.
#5
07/15/2005 (1:41 am)
But that's the strange thing...
Yes at first I also thought it may have been hardware related... but I'm using
the same client.cs file in both the old and the new T2D SDK...

The old SDK has no prolbem at all.. you can move around and shoot just fine

The new T2D SDK ver 1.2 with exactly the same client.cs file only moves up!
And the console comes up with:

(0) : Unable to find function playerRight
(0) : Unable to find function playerRightStop
(0) : Unable to find function playerLeft
etc... including playerFire


This is why I think the issue may be with some change in T2D v1.2?

Same hardware
Same Code
Only difference is: T2D old = Works. T2D 1.2 = only moves up

The syntax should be fine as it works fine in the old T2D... a pure syntax error should stop the old T2D from working as well (well I guess)

odd
#6
07/16/2005 (5:49 am)
Lower / Uppercase discrepancies:

In function definition:

>> playerUP()
>> playerUPStop()

Function calls (in action map):

>> playerUp()
>> playerUpStop

... which is weird since you're saying the 'up' action is the only one that works...
#7
07/16/2005 (6:06 am)
Odd... I got it working last night with 1.2
#8
07/16/2005 (6:16 am)
The playerDown, playerUp, playerLeft, playerRight etc. functions are in player.cs. It seems like your player.cs file is either not being exec() (which it should be in client.cs) or it is missing those functions. Only thing i can think of is to check those two things.
#9
07/16/2005 (7:00 am)
Yes UP and Up make no difference to waht happens...
mmm Russel this is from the basic tutorial and not the proper scroller demo... the basic tutorial does not split Sripting in different files

This is the whole code
Again.. this same code below works nife in the firts T2D release, but only moves up in T2D 1.2:
(maybe try on your own sdk to see if you get my same problem... I wouldn't be surprised if it is me
missing some really obvious stuff :)
Code below split in multiple posts because character lenth thread limits:



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

// --------------------------------------------------------------------
// Initialise Client.
// --------------------------------------------------------------------
function initialiseClient()
{
// Initialise Base Client.
InitBaseClient();

// Key-Bindings.
GlobalActionMap.bind(keyboard, tilde, ToggleConsole);
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");


// Initialise Canvas.
InitCanvas("T2D");


// ************************************************************************
// Load-up Demo Datablocks.
// NOTE:- Remove this is you're not interested in running the demos
// or any or the default datablocks.
// ************************************************************************
exec("./demoDatablocks.cs");



// Load-up Datablocks.
exec("./datablocks.cs");
// Load-up GUIs.
exec("./mainScreenGui.gui");

// Set GUI.
Canvas.setContent(mainScreenGui);
// Set Cursor.
Canvas.setCursor(DefaultCursor);

// Setup Scene.
setupT2DScene();
}


// --------------------------------------------------------------------
// Destroy Client.
//
// Here we destroy the SceneGraph.
// --------------------------------------------------------------------
function destroyClient()
{
// Destroy fxSceneGraph2D.
if ( isObject(t2dSceneGraph) )
t2dSceneGraph.delete();
}


// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function setupT2DScene()
{

// 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" );


// ************************************************************************
//
// Add your custom code here...


//Set up the images for the game by CALLING the SetupImages() function
SetupImages();


//Create player stuff calling the related function
CreatePlayer();


//Set up enemy
CreateEnemy();

//create tile MAP
CreateTileMap();




// ************************************************************************

}
'
// --------------------------------------------------------------------
// END SetupT2DScene()
// --------------------------------------------------------------------
#10
07/16/2005 (7:01 am)
// --------------------------------------------------------------------
//function to set up/CREATE images
function SetupImages()
{


//Create image for player ship
datablock fxImageMapDatablock2D(playershipImageMap)
{
mode = full;
textureName = "~/client/images/playerShip";
};

// Create an image for the player's missiles
datablock fxImageMapDatablock2D(playermissileImageMap)
{

mode = full;
textureName = "~/client/images/playerMissile";
};



// Create an image for the enemy ships
datablock fxImageMapDatablock2D(enemyship1ImageMap)
{
mode = full;
textureName = "~/client/images/enemyship1";
};

//ENEMY MISSILE GRAPHICS

datablock fxImageMapDatablock2D(enemymissileImageMap)
{
mode = full;
textureName = "~/client/images/enemyMissile";
};


//Images for Tile map-------
// Create images for the tilemap
datablock fxImageMapDatablock2D(bgBlankSkyImageMap)
{
mode = full;
textureName = "~/client/images/bg_blank_sky";
};
datablock fxImageMapDatablock2D(bgCloud1ImageMap)
{
mode = full;
textureName = "~/client/images/bg_cloud_1";
};
datablock fxImageMapDatablock2D(bgCloud2ImageMap)
{
mode = full;
textureName = "~/client/images/bg_cloud_2";
};
datablock fxImageMapDatablock2D(bgCloud3aImageMap)
{
mode = full;
textureName = "~/client/images/bg_cloud_3a";
};
datablock fxImageMapDatablock2D(bgCloud3bImageMap)
{
mode = full;
textureName = "~/client/images/bg_cloud_3b";
};




}
//END FUNCTION TO SET/CREATE IMAGES SetupImages()
// --------------------------------------------------------------------
#11
07/16/2005 (7:01 am)
// CREATE TILEMAP--------------------------------------MAP

function CreateTileMap()
{
// Create tile-map.
%scrollerMap = new fxTileMap2D() { scenegraph = t2dSceneGraph; };

// Load saved tile-map file.
%scrollerMap.loadTileMap("~/client/maps/scroller.map");

// Load tile layer from tile-map
%skyLayer = %scrollerMap.getTileLayer( 0 );

// Generate Scrolling Sky, re-size to fill the whole screen
%skyLayer.setPosition( "0 -10" );
%skyLayer.setTileSize( "25 25" );
%skyLayer.setWrap( true, false );
%skyLayer.setAutoPan( "10 0" );
}





// --------------------------------------------------------------------
//function to CREATE Player

function CreatePlayer()
{

//Create player
$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
$player.setPosition("-35 0");
$player.setSize( "14 7");
$player.setImageMap( playershipImageMap );
$player.fireLinkPoint = $player.addLinkPoint( "0.45 0.2" );
$player.setWorldLimit( clamp, "-49 -37 40 37" );

attachThruster( $player, "-0.12 -0.33", 0 );

// Set player's collision info:
$player.setGroup( 1 );
$player.setLayer( 1 );
$player.setCollisionActive( true, true );
$player.setCollisionMaterial( standardMaterial );
$player.setCollisionPolyCustom( 4, "-1 0 -0.1 -0.6 0.98 0.15 -0.1 0.7" );
$player.setCollisionMasks( BIT(2), BIT(2) );
$player.setCollisionCallback( true );



// 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();", "");

//Active the action map
playerMap.push();

}
//END function to CREATE Player--------------------


//PLAYER FIRE-------------------------------
function playerFire()
{
// Create player projectile.
%projectile = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%projectile.setPosition( $player.getLinkPoint($player.fireLinkPoint) );
%projectile.setSize( "3 1.5" );
%projectile.setImageMap( playermissileImageMap );
%projectile.setWorldLimit( kill, "-52 -40 52 40" );
%projectile.setLinearVelocityX( 50 );

// Setup collision info
%projectile.setGroup( 1 );
%projectile.setLayer( 1 );
%projectile.setCollisionActive(true, true);
%projectile.setCollisionMaterial(projectileMaterial);
%projectile.setCollisionScale("0.9 0.5");
%projectile.setCollisionMasks( BIT(2), BIT(2));
%projectile.setCollisionCallback( true );

}
#12
07/16/2005 (7:02 am)
// CRAEATE THE ENEMY FUNcTION-----------------------------------

function CreateEnemy()
{
// Create an enemy ship
%enemy = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemy.setImageMap( enemyship1ImageMap );
%enemy.setSize( "14 7" );
%enemy.setPosition("40" SPC (-30 + (getRandom() * 60)));

attachThruster( %enemy, "0.8 -0.12", 180 );
attachThruster( %enemy, "0.8 0.18", 180 );

// Move the enemy towards us.
%enemy.setLinearVelocityX(-35);
%enemy.setWorldLimit( kill, "-60 -40 60 40" );

// Set enemy collision info
%enemy.setGroup( 2 );
%enemy.setLayer( 2 );
%enemy.setCollisionActive( true, true );
%enemy.setCollisionMaterial( standardMaterial );
%enemy.setCollisionPolyCustom( 5, "-0.9 0 0 -0.6 1 -0.3 1 0.3 0 0.5" );
%enemy.setCollisionMasks( BIT(1), BIT(1) );
%enemy.setCollisionCallback( true );

// Create an enemy missile and fire it
%enemyFire = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemyFire.setPosition( %enemy.getPosition() );
%enemyFire.setSize( "3 1.5" );
%enemyFire.setImageMap( enemymissileImageMap );
%enemyFire.setLinearVelocityX( -45 );
%enemyFire.setWorldLimit( kill, "-60 -40 60 40" );

// Set up collision info
%enemyFire.setGroup( 2 );
%enemyFire.setLayer( 2 );
%enemyFire.setCollisionActive( true, true );
%enemyFire.setCollisionMaterial( standardMaterial );
%enemyFire.setCollisionScale("0.9 0.5");
%enemyFire.setCollisionMasks( BIT(1), BIT(1) );
%enemyFire.setCollisionCallback( true );

schedule(2000, 0, "CreateEnemy");
}

// END CRAEATE THE ENEMY FUCNTION-----------------------------------
#13
07/16/2005 (7:02 am)
// THRUSTERS------------------------
function attachThruster(%mountObj, %mountPosition, %angle)
{
// Create Player Thruster.
%thruster = new fxParticleEffect2D() { scenegraph = t2dSceneGraph; };
%thruster.loadEffect("~/client/effects/smallThruster.eff");
%thruster.mount( %mountObj, %mountPosition, 0, false );
%thruster.setRotation( %angle );
%thruster.playEffect();
}




// Create Explosion-----------------
function createExplosion( %object )
{

// Ignore if object not around anymore.
if ( !isObject(%object) )
return;

// Shockwave Explosion.
%explosion = new fxParticleEffect2D() { scenegraph = t2dSceneGraph; };
%explosion.loadEffect("t2d/client/effects/shockwave_burst.eff");
%explosion.setPosition( %object.getPosition() );
%explosion.setEffectLifeMode( kill, 0.1 );
%explosion.playEffect();
}




//NEW CODE FOR MOVING-----------------------
function playerUp()
{
//set the player moving up
$player.setLinearVelocityY( -20);
}

function playerUpStop()
{
//stop player from moving up IF YOU ARE MOVING UP!
if ( $player.getLinearVelocityY() < 0 )
$player.setLinearVelocityY( 0 );
}



function playerDown()
{
// Set the player moving down.
$player.setLinearVelocityY( 20 );
}
function playerDownStop()
{
// If we're moving down then nullify any downward movement.
if ( $player.getLinearVelocityY() > 0 )
$player.setLinearVelocityY( 0 );
}




function playerLeft()
{
// Set the player moving left.
$player.setLinearVelocityX( -20 );
}
function playerLeftStop()
{
// If we're moving left then nullify any leftward movement.
if ( $player.getLinearVelocityX() < 0 )
$player.setLinearVelocityX( 0 );
}




function playerRight()
{
// Set the player moving right.
$player.setLinearVelocityX( 20 );
}
function playerRightStop()
{
// If we're moving right then nullify any rightward movement.
if ( $player.getLinearVelocityX() > 0 )
$player.setLinearVelocityX( 0 );
}




// END NEW CODE FOR MOVING-----------------------
#14
07/16/2005 (7:02 am)
// KILL PLAYER-------------------------!

function KillPlayer()
{
$player.setVisible( false );
playerMap.pop();
schedule(2000, 0, "ResetPlayer");
}

//RESET PLAYER AFTER KILL---------------!
function ResetPlayer()
{
$player.setPosition("-35 0");
$player.setVisible(true);
playerMap.push();
}


//Function for COLLISSION------------------------------------
function fxSceneObject2D::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{

// Create an explosion for the collision that just occurred
createExplosion(%dstObj);

if(%srcObj == $player)
{
KillPlayer();
%dstObj.safeDelete();
}
else if (%dstObj == $player)
{
KillPlayer();
%srcObj.safeDelete();
}
else
{
%srcObj.safeDelete();
%dstObj.safeDelete();
}
}
#15
07/16/2005 (8:04 am)
I just tried this with sdk 1.02 copied your pasted text above and copied the images from the spacescroller example to the T2D directory and its working here. I did have to remove the ' in the pasted text:

'
// --------------------------------------------------------------------
// END SetupT2DScene()
// --------------------------------------------------------------------

But this was flagged in the console as an error so i assume that this was some copy and paste error.

Only thing i can suggest is get a fresh copy of sdk 1.02 installed and do the same as i did above. Then add your other code bit by bit.
#16
07/16/2005 (9:51 am)
Yes I think I should let this glitch be
it could be or some strange issue...
but I better move on to my main stuff with fresh code...
hopefully moving around with the new code will be fine... surley so

Thanks guys
I appreciate your time