Basic Movement Script In Torque Game Builder
by Meh... · in Technical Issues · 10/13/2006 (8:23 pm) · 10 replies
Hello everyone.
I am going through the movement tutorial with the fish demo. I follow the whole thing, but when I try to run the game, the fish is not responding to my movement keys. (wasd) Can anyone tell me what I've done wrong?
Here is my movement script;
function Playerfish::onLevelLoaded(%this, %scenegraph)
{
$FishPlayer=%this;
moveMap.bindCmd(keyboard,"w","fishPlayerUp();","PlayerfishUpStop();");
moveMap.bindCmd(keyboard,"s","fishPlayerDown();","PlayerfishDownStop();");
moveMap.bindCmd(keyboard,"a","fishPlayerLeft();","PlayerfishLeftStop();");
moveMap.bindCmd(keyboard,"d","fishPlayerRight();","PlayerfishRightStop();");
}
function fishPlayerUp()
{
$FishPlayer.setLinearVelocityY(-15);
}
function fishPlayerDown()
{
$FishPlayer.setLinearVelocityY(15);
}
function fishPlayerLeft()
{
$FishPlayer.setLinearVelocityX(-30);
}
function fishPlayerRight()
{
$FishPlayer.setLinearVelocityX(30);
}
function fishPlayerUpStop()
{
$FishPlayer.setLinearVelocityY(0);
}
function fishPlayerDownStop()
{
$FishPlayer.setLinearVelocityY(0);
}
function fishPlayerLeftStop()
{
$FishPlayer.setLinearVelocityX(0);
}
function fishPlayerRightStop()
{
$FishPlayer.setLinearVelocityX(0);
}
I am going through the movement tutorial with the fish demo. I follow the whole thing, but when I try to run the game, the fish is not responding to my movement keys. (wasd) Can anyone tell me what I've done wrong?
Here is my movement script;
function Playerfish::onLevelLoaded(%this, %scenegraph)
{
$FishPlayer=%this;
moveMap.bindCmd(keyboard,"w","fishPlayerUp();","PlayerfishUpStop();");
moveMap.bindCmd(keyboard,"s","fishPlayerDown();","PlayerfishDownStop();");
moveMap.bindCmd(keyboard,"a","fishPlayerLeft();","PlayerfishLeftStop();");
moveMap.bindCmd(keyboard,"d","fishPlayerRight();","PlayerfishRightStop();");
}
function fishPlayerUp()
{
$FishPlayer.setLinearVelocityY(-15);
}
function fishPlayerDown()
{
$FishPlayer.setLinearVelocityY(15);
}
function fishPlayerLeft()
{
$FishPlayer.setLinearVelocityX(-30);
}
function fishPlayerRight()
{
$FishPlayer.setLinearVelocityX(30);
}
function fishPlayerUpStop()
{
$FishPlayer.setLinearVelocityY(0);
}
function fishPlayerDownStop()
{
$FishPlayer.setLinearVelocityY(0);
}
function fishPlayerLeftStop()
{
$FishPlayer.setLinearVelocityX(0);
}
function fishPlayerRightStop()
{
$FishPlayer.setLinearVelocityX(0);
}
#2
10/13/2006 (10:53 pm)
Additionally, you may need to check and make sure that the main.cs is executing your movement script.
#3
Here is the game script that executes the file;
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
exec("./player.cs");
// Set The GUI.
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
moveMap.push();
if( isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
}
10/14/2006 (4:40 pm)
Hmm... Checked console in game, it said the file was missing, my script is a notepad file labled player.cs, could this be a problem?Here is the game script that executes the file;
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
exec("./player.cs");
// Set The GUI.
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
moveMap.push();
if( isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
}
#4
initialize the player.cs file.
If that is the case, you might want to move the line of code that reads...
exec("./player.cs");
... Into the main.cs file under the initializeProject function. Which would
look something like this...
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// initializeProject
// Perform game initialization here.
//---------------------------------------------------------------------------------------------
function initializeProject()
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");
// Exec game scripts.
exec("./gameScripts/game.cs");
exec("./gameScripts/player.cs");
... and so on.
Oh, and like Thomas said, you probably want to make sure the your classname
for your object corresponds to the name of the class in the player.cs file.
10/14/2006 (5:19 pm)
The only thing I am thinking is that the file you are using is the game.cs to initialize the player.cs file.
If that is the case, you might want to move the line of code that reads...
exec("./player.cs");
... Into the main.cs file under the initializeProject function. Which would
look something like this...
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// initializeProject
// Perform game initialization here.
//---------------------------------------------------------------------------------------------
function initializeProject()
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");
// Exec game scripts.
exec("./gameScripts/game.cs");
exec("./gameScripts/player.cs");
... and so on.
Oh, and like Thomas said, you probably want to make sure the your classname
for your object corresponds to the name of the class in the player.cs file.
#5
So the files try to execute it, but they can't see it?
This is the only error in the console, why can't it see the file?
"Missing file: MyFishDemo/gamescripts/player.cs"
10/14/2006 (5:47 pm)
I put in a command to execute the player.cs file in the main script. Still, nothing. So the files try to execute it, but they can't see it?
This is the only error in the console, why can't it see the file?
"Missing file: MyFishDemo/gamescripts/player.cs"
#6
10/14/2006 (5:49 pm)
Oh, and also, when I try to capitalize the "F" in Playerfish while in TGB editing the fish's class, it automatically makes it "Playerfish." Is this supposed to happen?
#7
10/14/2006 (6:22 pm)
You should really post this in the private forums for TGB
#8
Sorry for the wrong thread location.
10/14/2006 (6:25 pm)
I didn't really see that anywhere, mind giving me a link?Sorry for the wrong thread location.
#9
10/14/2006 (6:32 pm)
Ah, found it, moving.
#10
Check to make sure your player.cs files is truly named player.cs, and not player.cs.txt.
10/15/2006 (3:59 pm)
I've actually run into this a couple of times recently: Notepad likes to sneak in a hidden .txt on the end of your files when you first save them, and then of course the default windows settings for explorer is to hide extensions, so you never see it.Check to make sure your player.cs files is truly named player.cs, and not player.cs.txt.
Torque Owner Thomas Buscaglia