Game Development Community

Please Help A Newbie :)

by Malex Olton · in Torque Developer Network · 10/28/2009 (9:58 pm) · 12 replies

Hey guys I'm new to the whole Torque/Coding scene anyways I've come across a problem the script looks alright to me not sure if I'm not seeing something i should be seeing i even used the files from the tutorial I'm trying to complete yet i still get an error in the demo version of Torsion and my sprite isn't moving when i press w,a,s,d so could someone take a look at this and help me figure out what might be wrong?

function BattyPlayer::onLevelLoaded(%this, %scenegraph)
{
$MeBatty = %this;
moveMap.bindCmd(keyboard, “w”, “BattyPlayerUp();”, “BattyPlayerUpStop();”);
moveMap.bindCmd(keyboard, “s”, “BattyPlayerDown();”, “BattyPlayerDownStop();”);
moveMap.bindCmd(keyboard, “a”, “BattyPlayerLeft();”, “BattyPlayerLeftStop();”);
moveMap.bindCmd(keyboard, “d”, “BattyPlayerRight();”, “BattyPlayerRightStop();”);
}

function BattyPlayerUpStop()
{
$BattyPlayer.setLinearVelocityY(0);
}

function BattyPlayerDownStop()
{
$BattyPlayer.setLinearVelocityY(0);
}

function BattyPlayerLeftStop()
{
$BattyPlayer.setLinearVelocityX(0);
}

function BattyPlayerRightStop()
{
$BattyPlayer.setLinearVelocityX(0);
}

function BattyPlayerUp()
{
$BattyPlayer.setLinearVelocityY(-15);
}

function BattyPlayerDown()
{
$BattyPlayer.setLinearVelocityY(15);
}

function BattyPlayerLeft()
{
$BattyPlayer.setLinearVelocityX(-25);
}

function BattyPlayerRight()
{
$BattyPlayer.setLinearVelocityX(25);
}

I'm new to this plus I'm kinda tired so if its a super newbie mistake be gentle haha.

About the author

Recent Threads


#1
10/29/2009 (2:57 am)
Change

$MeBatty = %this;

to

$BattyPlayer = %this;

And see if that fixes your problem. Good luck.
#2
10/29/2009 (1:34 pm)
Hey Aun thanks for the help tho it didn't work this is the error that i get in Torison.

Precompiling...

//-------------------------- 10/29/2009 -- 12:28:16 -----
Compiling C:/Users/Documents/Game Projects/Project RO/game/gameScripts/player.cs...
C:/Users/Documents/Game Projects/Project RO/game/gameScripts/player.cs Line: 4 - parse error
>>> Advanced script error report. Line 4.
>>> Some error context, with ## on sides of error halt:
unction BattyPlayer::onLevelLoaded(%this, %scenegraph)
{
$BattyPlayer = %this;
moveMap.bindCmd(keyboard, “w”, “BattyPlayerUp();”, “BattyPlayerUpStop();”);
## ## moveMap.bindCmd(keyboard, “s”, “BattyPlayerDown();”, “BattyPlayerDownStop();”);
moveMap.bindCmd(keyboard, “a”, “BattyPlayerLeft();”, “BattyPlayerLeftStop();”);
moveMap.bindCmd(keyboard, “d”, “BattyPlayerRight();”, “BattyPlayerRightStop();”);
}

function BattyPlayerUpStop()
>>> Error report complete.

Compiling C:/Users/Documents/Game Projects/Project RO/game/managed/brushes.cs...

Project RO - 2 scripts(s), 1 error(s)

It would be the same when i change $MeBatty to $MeBattyPlayer
#3
10/29/2009 (2:25 pm)
Your syntax all appears correct. Have you edited this file with anything other than Torsioin (notepad, wordpad, etc)?
#4
10/29/2009 (2:52 pm)
I used wordpad before then when i got problems i decided to check it out in Torsion.
#5
10/29/2009 (3:41 pm)
That's where your problem is coming from. Wordpad has a tendency to add extra binary garbage to files that, while not visible within the editor, breaks the file entirely. The only way to fix this is to create a new file as the extra data cannot be deleted using a text editor. When you make your new script make sure not to copy/paste anything from the old script into the new one as you run the risk of copying the problem data into the new file.

Also, for script editing options I recommend:
Torsion - default choice for TorqueScript editing
TorqueDev - TorqueScript IDE created by community member Sam Bacsa
Notepad++ - Open Source text editor designed to be simple like notepad but capable of handling multiple different programming languages
#6
10/29/2009 (11:10 pm)
Oh wow i never knew that thanks alot I'll get to work then also thanks for the recommendations!
#7
10/30/2009 (12:53 am)
No problem, it's something that not a lot of people know about right off the bat. I spent 3 years working with Torque tech before it happened to me.
#8
10/30/2009 (1:57 am)
Yeah, it's the BOM thing at the beginning of a UTF-8 file saved in certain editors. Notepad++ should have an option to strip it.
#9
10/30/2009 (3:17 am)
Well I've done it in Torison but it appears that there's a new problem...
Haha fix one get another one :(

game/gameScripts/player.cs (12): Unable to find object: '' attempting to call function 'setLinearVelocityY'

Weird i set the class and everything I'm sure..

function BattyPlayer::onLevelLoaded(%this, %scenegraph)
{
$MeBatty = %this;
moveMap.bindCmd(keyboard, "w", "BattyPlayerUp();", "BattyPlayerUpStop();");
moveMap.bindCmd(keyboard, "s", "BattyPlayerDown();", "BattyPlayerDownStop();");
moveMap.bindCmd(keyboard, "a", "BattyPlayerLeft();", "BattyPlayerLeftStop();");
moveMap.bindCmd(keyboard, "d", "BattyPlayerRight();", "BattyPlayerRightStop();");
}

function BattyPlayerUp()
{
$BattyPlayer.setLinearVelocityY(-15);
}
function BattyPlayerDown()
{
$BattyPlayer.setLinearVelocityY(15);
}
function BattyPlayerLeft()
{
$BattyPlayer.setLinearVelocityX(-25);
}
function BattyPlayerRight()
{
$BattyPlayer.setLinearVelocityX(25);
}

function BattyPlayerUpStop()
{
$BattyPlayer.setLinearVelocityY(0);
}
function BattyPlayerDownStop()
{
$BattyPlayer.setLinearVelocityY(0);
}
function BattyPlayerLeftStop()
{
$BattyPlayer.setLinearVelocityY(0);
}
function BattyPlayerRightStop()
{
$BattyPlayer.setLinearVelocityY(0);
}

Is that not correct?
#10
10/30/2009 (6:00 am)
I still insist you to change

$MeBatty = %this;

to

$BattyPlayer = %this;

:)
#11
10/30/2009 (2:13 pm)
Oh i forgot you told me to change that before Aun my bad :P
I'll go do that now that its been learned wordpad is evil thanks again.
#12
10/30/2009 (3:27 pm)
Thanks everyone for all your help things are working how they should!