Game Development Community

Tgb 2d demo problems

by Ryan Cabaruvas · in Technical Issues · 06/28/2008 (3:51 pm) · 12 replies

I am very new to tgb and I am having the same issue in both the fishgame demo and the shootergame demo. I can not successfully bind keys in either of them. I have made a player.cs file and it is not a .txt, it is correctly a visual c# source file. I have also made in exec command in the game.cs file for the player.cs. The static sprite the demo tells me to put in the game also has its class correctly specified and has the name the demo gives. However, when I run the game the static sprite shows, but my keys do move the ship at all.
Here is the scripts I made for the game.cs and the player.cs for the shootergame demo

game.cs:
//---------------------------------------------------------------------------------------------
// 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("./gameScripts/player.cs");

Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);

new ActionMap(moveMap);
moveMap.push();

$enableDirectInput = true;
activateDirectInput();
enableJoystick();

sceneWindow2D.loadLevel(%level);
}

//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}

player.cs:
function playerShip::onLevelLoaded(%this, %scenegraph)
{
//set the player's ship name to the instance
$pShip = %this;

moveMap.bindCmd(keyboard, "w", "pShipUp();", "pShipUpStop();");
moveMap.bindCmd(keyboard, "s", "pShipDown();", "pShipDownStop();");
moveMap.bindCmd(keyboard, "a", "pShipLeft();", "pShipLeftStop();");
moveMap.bindCmd(keyboard, "d", "pShipRight();", "pShipRightStop();");
}

function playerShip::updateMovement(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX( -$pShip.hSpeed );
}

if(%this.moveRight)
{
%this.setLinearVelocityX( $pShip.hSpeed );
}

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

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

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

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

function pShipUp()
{
$pShip.moveUp = true;
$pShip.updateMovement();
}

function pShipDown()
{
$pShip.moveDown = true;
$pShip.updateMovement();
}

function pShipLeft()
{
$pShip.moveLeft = true;
$pShip.updateMovement();
}

function pShipRight()
{
$pShip.moveRight = true;
$pShip.updateMovement();
}

function pShipLeftStop()
{
$pShip.moveLeft = false;
$pShip.updateMovement();
}

function pShipRightStop()
{
$pShip.moveRight = false;
$pShip.updateMovement();
}

function pShipUpStop()
{
$pShip.moveUp = false;
$pShip.updateMovement();
}

function pShipDownStop()
{
$pShip.moveDown = false;
$pShip.updateMovement();
}

*also note the spacing doesnt show up in the post but between the { and} I have some spaced like the demo shows

#1
06/28/2008 (7:57 pm)
*.cs files are script C files. Microsoft VS doesn't compile those, the torque engine does.
If you have your compiler setup to associate *.cs files as C# files, that could be your problem?

Try going to your MyAccount here at GG and Download Torsion, associate your *.cs files with Torsion instead.
This way when you save the file in Torsion, the .cs extension will be correctly added to your file name.
Torsion should be your default editor / debugger for *.cs files.

It's a poke in the dark, but this seems logical to do. Since your unmodified sprite file loads as it should, but your other modified files in your Compiler do not.

I didn't read your code at all yet because your comments above the code, tells me your compiler is associating .cs files as if it was a C# and it would show in the compiler, but when you save changes to that file it likely gets another extension added.. something like MyFile.cs.c

If your certian this is not the case, then try deleting all the *.dso files first. These *.dso files are the compiled *.cs files that the engine makes at start-up.

Then, start your game as usual and open command window ( the TGB command window ) and see if your Player.cs and game.cs files are compiled and loaded.
If those 2 files were compiled and loaded normally then we can scout for the error in the code or possibly the Path to your files.


(edited Typos )
#2
06/28/2008 (10:27 pm)
Well I got the free version of torsion for now and set the .cs files to open with torsion now, but whenever I save them through torsion they remain the same. When I go to play the game it remains the same with no response from binded keys, likewise after removing the .dso files, the keys are still responsive. As for the tgb command window, I am still very new to this so I don't know what that is.
#3
06/29/2008 (12:39 am)
I'm very new to TGB too but I was wondering doesn't it say in the shooter tutorial to add the line

exec("./gameScripts/player.cs");

to game/main.cs

and not to game.cs as you have done?

I added all the lines in the same as you and everything worked ok for me.
#4
06/29/2008 (4:29 am)
Ryan, I have been using TGE so thats why I mentioned the Command Window.

I will reinstall TGB and run through the project demo to reach the point your at and see if I get that same problem and fix it.
What version of TGB are you using ?, 1.7.3 ?
#5
06/29/2008 (5:47 am)
For the Fish demo game...

game.cs will be in this directory:
...\game\gameScripts\game.cs

function startGame(%level)
{
   exec("./player.cs");

   Canvas.setContent(mainScreenGui);
   Canvas.setCursor(DefaultCursor);
   
   new ActionMap(moveMap);   
   moveMap.push();
   
   $enableDirectInput = true;
   activateDirectInput();
   enableJoystick();
   
   sceneWindow2D.loadLevel(%level);
}

//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
   sceneWindow2D.endLevel();
   moveMap.pop();
   moveMap.delete();
}

player.cs will be in this directory: \game\gameScripts\player.cs

function PlayerFish::onLevelLoaded(%this, %scenegraph)
{
   $FishPlayer = %this;


   moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();");
   moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();");
   moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();");
   moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();");
}


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 );
}


Your projects Level / scene, wil be saved in your
C:\Program Files\GarageGames\TorqueGameBuilder-1.7.3\games\BehaviorShooter\game\data\levels\ folder. (for the Shooter game, as example ).
Each project like the fish demo or the shooter demo will have it's own "data/levels" directory.

If your Player.cs file for the fish game looks like this, and your game.cs file looks like this, and both are saved in the proper directory, then your game will work for you.

If this doesn't work for you, then post back .. and we will find why it doesn't.

(famous for typo corrections)
(Edited the Player.cs file )
#6
06/29/2008 (6:21 pm)
Yes, I have 1.7.3 and I fixed just spacing from single to double to match yours and it still doesn't work, however a player.cs.dso was generated after I used torsion so I think it recognizes the player.cs file now. But, still when I hit play scene or run game the fish does not move. Also at the bottem of your player.cs script where did the
$FishPlayer.setLinearVelocityXt2dSceneObject::setLinearVelocityX(float velocityX)( 0 ); of the function fishPlayerRightStop() come from? My Guide has it only as $FishPlayer.setLinearVelocityX( 0 );
*oh one more thing where is the command window?
#7
06/30/2008 (1:28 pm)
I apologise Ryan, that last line didn't belong there in player.cs
I didn't work through the Fish Demo ahead of time so working that demo now so I can replicate
what you see.

Ok Ryan, I completed that tutorial. it works as intended.
Here is what I did:

Documentation reads 1 - Starting Out
Start TGB
Create a new Project:
Make a new project named it "MyFishGame" and with no templates selected.
Import the "fishArt" resource

Documentation reads 2 - Moving a Fish
So we select a fish and drag it to the scene area.
Change the fish's class to 'PlayerFish' (Without the quotes)
Save the level as "myFishlevel" ( Without the quotes )
(Saving a level puts it in the "data/levels" folder of your project)

Documentation reads 2.3 Creating our movement script file
( Your player.cs file is where the movement functions are and it looks like this: )
function PlayerFish::onLevelLoaded(%this, %scenegraph)
{
   $FishPlayer = %this;


   moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();");
   moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();");
   moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();");
   moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();");
}


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 );
}

And it is saved into your Game directory.. On my system that player.cs file is in:
C:\MyGames\MyFishGame\game\gameScripts\player.cs

Then we exec ( execute ) our player.cs file from the game.cs file.
(The game.cs file on my system is in : )
C:\MyGames\MyFishGame\game\gameScripts\game.cs

at the top of the file we see this:
function startGame(%level)
{
   exec("./player.cs");   // <-- here is where the documentation says to exec our player.cs file

   Canvas.setContent(mainScreenGui);
   Canvas.setCursor(DefaultCursor);
   
   new ActionMap(moveMap);   
   moveMap.push();
   
   $enableDirectInput = true;
   activateDirectInput();
   enableJoystick();
   
   sceneWindow2D.loadLevel(%level);
}

When you have saved your game.cs and saved your player.cs files in the same directory as listed above
and listed here ( C:\MyGames\MyFishGame\game\gameScripts\ )
Then we can build the game.
The documentation says to play it.. I just went ahead and built it.
I had to change the directories to match my game folder, and to point out the folder for my game.cs and player.ce files.

This is probably why yours isn't working.. it's not finding the project and all the files.
Go to File > Build Project...
a small window will show up:

Company Name Independant
Product Name MyFishGame
Startup Scene game/data/levels/myFishlevel.t2d
Output Directory ( I placed mine on desktop here )
Platform Windows

and I checked the box "Include Script Source"
and i pressed the "Build" button

What i got was a new Folder on my desktop with all the files I need for my fish game.
While the folder was open to me, after it was built, I simply clicked the MyFishGame.exe Icon, and tested it for movement. It worked as intended.
#8
07/03/2008 (5:06 pm)
Sorry it took so long to get back to this, I was very busy these last two days. I completed your instructions and sadly produced the same results, when I click RyanFishGame.exe Icon (I named mine after my name is that ok?) it produced the same screen as before: Black with the fish where I left it. None of the keys move it and there is no icons or options on the screen exept for the top right minimize or exit buttons. In the actualy folder of the game I took a look around in the console text file that was generated and found it failed to load a GL function, is this possible the problem?
console text:
//-------------------------- 7/3/2008 -- 16:57:48 -----
Processor Init:
AMD (unknown), ~2.10 Ghz
(timed at roughly 2.10 Ghz)
FPU detected
MMX detected
3DNow detected
SSE detected

Math Init:
Installing Standard C extensions
Installing Assembly extensions
Installing FPU extensions
Installing MMX extensions
Installing 3DNow extensions
Installing SSE extensions

Input Init:
DirectInput enabled.

Initializing chunk mappings...
Could not load this GL function: glGenTextures
Could not load this GL function: glBindTexture
Could not load this GL function: glTexImage2D
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glGenTextures
Could not load this GL function: glBindTexture
Could not load this GL function: glTexImage2D
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
Could not load this GL function: glTexParameteri
o 'TEXT' maps to TextChunk
o 'SCHK' maps to UnknownChunk
o 'SCHK' maps to SimChunk
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/main.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/main.cs.
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/game/main.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/game/main.cs.
% - Initializing Common
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/preferences/defaultPrefs.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/preferences/defaultPrefs.cs.
Reading Display Device information...
Primary Display Device Found:
Vendor Id: VEN_0000
Device Id: DEV_0000

Using OpenGL rendering. Fullscreen: 0

Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/xml.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/xml.cs.
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/properties.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/properties.cs.
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/common.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/common.cs.
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/audio.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/audio.cs.
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/canvas.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/canvas.cs.
Compiling C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/cursor.cs...
Loading compiled script C:/Documents and Settings/ryan/Desktop/RyanFishGame/common/gameScripts/cursor.cs.
Video Init:
Accelerated OpenGL display device detected.
Accelerated D3D device detected.
Voodoo 2 display device not detected.

Activating the OpenGL display device...
Activating the OpenGL display device...
Setting screen mode to 800x600x32 (w)...
Creating a new window...
Acquiring a new device context...
Pixel format set:
32 color bits, 24 depth bits, 8 stencil bits
Creating a new rendering context...
Making the new rendering context current...
OpenGL driver information:
Vendor: NVIDIA Corporation
Renderer: GeForce 6100 nForce 405/PCI/SSE2/3DNOW!
Version: 2.0.3
OpenGL Init: Enabled Extensions
ARB_multitexture (Max Texture Units: 4)
EXT_blend_color
EXT_blend_minmax
EXT_compiled_vertex_array
NV_vertex_array_range
EXT_texture_env_combine
EXT_packed_pixels
EXT_fog_coord
ARB_texture_compression
EXT_texture_compression_s3tc
(ARB|EXT)_texture_env_add
EXT_texture_filter_anisotropic (Max anisotropy: 16)
WGL_EXT_swap_control
OpenGL Init: Disabled Extensions
EXT_paletted_texture
3DFX_texture_compression_FXT1

Max Texture Size reported as: 4096
OpenAL Driver Init:
Vendor: Creative Labs Inc.
Version: OpenAL 1.0
Renderer: Software
Extensions: EAX 2.0, EAX 3.0, EAX Unified, and EAX-AC3
*continues on to load script

Thank you for continued help
#9
07/04/2008 (5:47 am)
Ryan, could you edit that post above to include the entire console.log file please.
The important part is not included in the post,.. the part that loads your game files.

Also at the bottom of the window that you type in to reply.. there is a help menu for posting your file as code and makes your post easier to read.

I'm watching your thread, so go ahead and post the entire console.log file.

Thanks
#10
07/05/2008 (1:58 pm)
Ok I have figured out the problem. I tried textpad instead of notepad this time and it worked fine, notepad made them into .cs files, but I guess for some reason it still didn't work. Likewise torsion for some reason opened the text files with notepad, so I think they both had the same problems. Now I can move the fish and the fighter in both demos, so Thank You for all your help.
#11
07/06/2008 (9:49 am)
Glad you have it fixed.
Another great reason for using Torsion instead instead is that you can debug your scripts with it.
Just suggesting to use Torsion for all your .cs files because it will save you headaches.
#12
04/13/2009 (5:11 pm)
Something to note: Torque will not compile a .cs file which has an error within it.