Game Development Community

Newbie needs some help with the tutorials

by nick fortier · in Technical Issues · 05/15/2011 (9:26 pm) · 5 replies

So I've been running through the fish tutorial, I've got the fish moving but now Im at the adjusting movement part and am having lots of problems.I've gone through the code and it seems all correct, but it doesn't work when I run the game.

First is trying to put in the boost for my fish, Im pretty sure this is all correct, have a look.
Boost
function mainPlayerBoost()
{
%flipX=$MainPlayer.getFlipX();

if(!%flipX)
{
%hSpeed=$MainPlayer.hSpeed * 3;
}else
{
%hSpeed=-$MainPlayer.hSpeed * 3;
}
$MainPlayer.setLinearVelocityX(%hSpeed);
}
function MainPlayerBoostStop()
{
$MainPlayer.setLinearVelocityX(0);
}



Next is trying to smooth out my fish movements. Im not exactly sure what Im all doing here, but Im pretty sure the code is all correct.

function MainPlayer::updateMovement(%this)
{
if(%this.moveLeft)
{
$MainPlayer.setFlipX(true);
$MainPlayer.setLinearVelocityX(-$MainPlayer.hSpeed);
}

if(%this.moveRight)
{
$MainPlayer.setFlipX(false);
$MainPlayer.setLinearVelocityX($MainPlayer.hSpeed);
}

if(%this.moveUp)
{

%this.setLinearVelocityY(-$MainPlayer.uSpeed);
}

if(%this.moveDown)
{

%this.setLinearVelocityY($MainPlayer.bSpeed);
}

if(!%this.moveLeft&& !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
if(!%this.moveUp&& !%this.moveDown)
{
%this.setLinearVelocityY(0);
}
}


function mainPlayerUp()
{
$MainPlayer.moveUp=true;
$MainPlayer.updateMovement();
}

function mainPlayerDown()
{
$MainPlayer.moveDown=true;
$MainPlayer.updateMovement();
}

function mainPlayerLeft()
{
$MainPlayer.moveLeft=true;
$MainPlayer.updateMovement();
}

function mainPlayerRight()
{
$MainPlayer.moveRight=true;
$MainPlayer.updateMovement();
}

function mainPlayerUpStop()
{
$MainPlayer.moveUp=false;
$MainPlayer.updateMovement();
}

function mainPlayerDownStop()
{
$MainPlayer.moveDown=false;
$MainPlayer.updateMovement();
}

function mainPlayerLeftStop()
{
$MainPlayer.moveLeft=false;
$MainPlayer.updateMovement();
}

function mainPlayerRightStop()
{
$MainPlayer.moveRight=false;
$MainPlayer.updateMovement();
}

Lastly Anyone know some good resources that break down programming into a easy to understand way. Making games have always been a dream of mine, I've got the art skills and creativity I just need the programming knowledge.

#1
05/16/2011 (5:45 am)
Check out C++ In 21 Days for a great place to get started on programming.
#2
05/16/2011 (4:49 pm)
Nick, if your code isn't working, check the console while in game (press the ~ button) or if you've closed out the game, look in the folder with the torque.exe for a file called "console.log". Open it in any word editor to read it. (it's just a text file printed out by the console) Look for any errors.
#3
05/17/2011 (3:41 am)
Thanks for the tips I'll try those out.
#4
05/17/2011 (6:58 pm)
Hmm still having lots of problems. This is from the console.log:


Compiling /Users/nickfortier/MyGames/FishGame/game/gameScripts/player.cs...
/Users/nickfortier/MyGames/FishGame/game/gameScripts/player.cs Line: 4 - parse error
>>> Advanced script error report. Line 4.
>>> Some error context, with ## on sides of error halt:
function MainPlayer::onLevelLoaded(%this, %scenegraph)
//adjust movement

function MainPlayer::updateMovement(%this)
##{##
if(%this.moveLeft)
{
$MainPlayer.setFlipX(true);
$MainPlayer.setLinearVelocityX(-$MainPlayer.hSpeed);
}

if(%this.moveRight)
{
$MainPlayer.setFlipX(false);
$MainPlayer.setLinearVelocityX($MainPlayer.hSpeed);
}


>>> Error report complete.

game/gameScripts/game.cs (22): Unable to find function enableJoystick
Compiling /Users/nickfortier/MyGames/FishGame/game/data/levels/untitled.t2d.t2d...
creating path /Users/nickfortier/MyGames/FishGame/game/data/levels/untitled.t2d.t2d.dso
Loading compiled script /Users/nickfortier/MyGames/FishGame/game/data/levels/untitled.t2d.t2d.
creating path /Users/nickfortier/Library/Application Support/Independent/UntitledGame/common/commonConfig.xml
Shutting down the OpenGL display device...
Cleaning up the display device...
Killing the texture manager...
Clearing the current AGL context...
Clearing the current drawable...
Deleting the rendering context...
Destroying the window...

Also if you care to look this is my code. Its taken directly from the tutorial so Im not sure what wrong.

function MainPlayer::onLevelLoaded(%this, %scenegraph)
//adjust movement

function MainPlayer::updateMovement(%this)
{
if(%this.moveLeft)
{
$MainPlayer.setFlipX(true);
$MainPlayer.setLinearVelocityX(-$MainPlayer.hSpeed);
}

if(%this.moveRight)
{
$MainPlayer.setFlipX(false);
$MainPlayer.setLinearVelocityX($MainPlayer.hSpeed);
}

if(%this.moveUp)
{
%this.setLinearVelocityY(-$MainPlayer.vSpeed);
}


if(%this.moveDown)
{
%this.setLinearVelocityY($MainPlayer.vSpeed);
}


if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}


if(!%this.moveUp && !%this.moveDown)
{
%this.setLinearVelocityY( 0 );
}
}


//Keybindings
{
$MainPlayer=%this;
moveMap.bindCmd(keyboard, "space", "mainPlayerBoost();", "MainPlayerBoostStop();");
moveMap.bindCmd(keyboard, "up","mainPlayerUp();","MainPlayerUpStop();");
moveMap.bindCmd(keyboard, "down","mainPlayerDown();","MainPlayerDownStop();");
moveMap.bindCmd(keyboard, "left","mainPlayerLeft();","MainPlayerLeftStop();");
moveMap.bindCmd(keyboard, "right","mainPlayerRight();","MainPlayerRightStop();");
}



//speed functions
function mainPlayerUp()
{
$MainPlayer.moveUp=true;
$MainPlayer.updateMovement();
}

function mainPlayerDown()
{
$MainPlayer.moveDown=true;
$MainPlayer.updateMovement();
}

function mainPlayerLeft()
{
$MainPlayer.moveLeft=true;
$MainPlayer.updateMovement();
}

function mainPlayerRight()
{
$MainPlayer.moveRight=true;
$MainPlayer.updateMovement();
}


function MainPlayerUpStop()
{
$MainPlayer.moveUp=false;
$MainPlayer.updateMovemen():
}

function MainPlayerDownStop()
{
$MainPlayer.moveDown=false;
$MainPlayer.updateMovemen():
}

function MainPlayerLeftStop()
{
$MainPlayer.moveLeft=false;
$MainPlayer.updateMovemen():
}

function MainPlayerRightStop()
{
$MainPlayer.moveRight=false;
$MainPlayer.updateMovemen():
}
//Boost
function mainPlayerBoost()
{
%flipX = $MainPlayer.getFlipX();


if(!%flipX)
{
%hSpeed = $MainPlayer.hSpeed * 3;
} else
{
%hSpeed = -$MainPlayer.hSpeed * 3;
}


$MainPlayer.setLinearVelocityX(%hSpeed);
}
function mainPlayerBoostStop()
{
$MainPlayer.setLinearVelocityX(0);
}
#5
05/17/2011 (10:37 pm)
Quote:
Compiling /Users/nickfortier/MyGames/FishGame/game/gameScripts/player.cs...
/Users/nickfortier/MyGames/FishGame/game/gameScripts/player.cs Line: 4 - parse error
>>> Advanced script error report. Line 4.
>>> Some error context, with ## on sides of error halt:
function MainPlayer::onLevelLoaded(%this, %scenegraph)
//adjust movement

function MainPlayer::updateMovement(%this)
##{##
That's a helluva syntax error right there. A function definition cannot contain another function definition. If MainPlayer::onLevelLoaded() is intended to be a stub (empty) function then you need to begin and close it off with brackets:
function MainPlayer::onLevelLoaded() 
{
   // nothing here
}
Then you can begin the MainPlayer::updateMovement() function. The execution of the script fails because of the syntax/parse error and none of it's contents are loaded up past that point.