Game Development Community

Problem in Asteroids tutorial

by David froberg · in Torque Game Builder · 08/29/2011 (8:22 pm) · 4 replies

Hi everyone,
I'm having the following problems, can anyone shed some light?:

ctivating DirectInput...
DirectInput joystick failed to enable!
Compiling C:/Users/Froberg/Documents/MyGames/Asteroids/game/data/levels/mainLevel.t2d...
Loading compiled script C:/Users/Froberg/Documents/MyGames/Asteroids/game/data/levels/mainLevel.t2d.
t2dSceneGraph::addToScene() - Object '1387' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1398' is already in a SceneGraph!.
DirectInput deactivated.
t2dSceneGraph::addToScene() - Object '1408' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1415' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1422' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1429' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1436' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1443' is already in a SceneGraph!.
game/behaviors/scorePoints.cs (21): Unable to find object: 'scoreObject' attempting to call function 'getBehavior'
game/behaviors/scorePoints.cs (21): Unable to find object: 'scoreObject' attempting to call function 'getBehavior'




the game seems to work, but the small explosion effects don't happen.
I tried to write a behavior that tells me what the objects are, but no object seems to match the problems.

My behavior:

if (!isObject(Object_IDBehavior))
{
%template = new BehaviorTemplate(Object_IDBehavior);

%template.friendlyName = "Object_ID_printer";
%template.behaviorType = "Game";
%template.description = "Prints object id in console";
}

function Object_IDBehavior::onLevelLoaded(%this, %scenegraph)
{
echo("The object is " @ %this);
echo("The object is " @ %this.owner.internalName);
}

function Object_IDBehavior::onAddToScene(%this)
{
echo("The object is " @ %this);
echo("The object is " @ %this.owner.internalName);
}



my console output with my behavior:

Compiling C:/Users/Froberg/Documents/MyGames/Asteroids/game/data/levels/mainLevel.t2d...
Loading compiled script C:/Users/Froberg/Documents/MyGames/Asteroids/game/data/levels/mainLevel.t2d.
The object is 1351
The object is
The object is 1351
The object is
t2dSceneGraph::addToScene() - Object '1388' is already in a SceneGraph!.
The object is 1396
The object is
t2dSceneGraph::addToScene() - Object '1400' is already in a SceneGraph!.
The object is 1408
The object is
t2dSceneGraph::addToScene() - Object '1409' is already in a SceneGraph!.
The object is 1417
The object is
DirectInput deactivated.
t2dSceneGraph::addToScene() - Object '1420' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1427' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1434' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1441' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1448' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1455' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1462' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1469' is already in a SceneGraph!.
t2dSceneGraph::addToScene() - Object '1476' is already in a SceneGraph!.
game/behaviors/scorePoints.cs (21): Unable to find object: 'scoreObject' attempting to call function 'getBehavior'
game/behaviors/scorePoints.cs (21): Unable to find object: 'scoreObject' attempting to call function 'getBehavior'
Shutting down the OpenGL display device...
Making the GL rendering context not current...
Deleting the GL rendering context...
Releasing the device context...


my score points.cs:

//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
// Behavior by Mike Lilligreen for TDN Asteroids Tutorial
//-----------------------------------------------------------------------------

if (!isObject(ScorePointsBehavior))
{
%template = new BehaviorTemplate(ScorePointsBehavior);

%template.friendlyName = "Score Points";
%template.behaviorType = "Game";
%template.description = "Gives the object a point value for scoring purposes";

%template.addBehaviorField(pointValue, "How much the object is worth", int, 10);
%template.addBehaviorField(counter, "The score counter object", object, "", t2dSceneObject);
}

function ScorePointsBehavior::onRemove(%this)
{
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
{
return;
}

$currentScore = $currentScore + %this.pointValue;
%counter.updateScore();
}


THANKS FOR THE HELP!

#1
08/30/2011 (9:45 pm)
I'm a bit confused by all of this, could you elaborate on it, or perhaps just rephrase? I admit I haven't looked at the asteroids tutorial, but it sounds like this might be a scripting error, somewhere.

I'm just confused at the moment I'm afraid ^^;
#2
08/30/2011 (10:55 pm)
Thank you thank you Thank you thank you Thank you thank you for responding.

I'm sure it is something obvious but I don't have enough knowledge to get myself out of the hole.

At this point there are 2 problems and they are most likely related.
I get lots of these in the console:
t2dSceneGraph::addToScene() - Object '1420' is already in a SceneGraph!.


the tutorial has a behavior that is supposed to prevent this (I think):


if (!isObject(TemplateBehavior))
{
%template = new BehaviorTemplate(TemplateBehavior);

%template.friendlyName = "Template";
%template.behaviorType = "Game";
%template.description = "Disables an object unless it is a clone";
}

function TemplateBehavior::onLevelLoaded(%this, %scenegraph)
{
%this.owner.enabled = false;
}

I have gone back and double checked that all my sprites and effects have this. But I still get get:
t2dSceneGraph::addToScene() - Object '1420' is already in a SceneGraph!.

I added a behavior to my objects that I hoped would print out the object name and ID so I could figure out what was calling addToScene(). But none of the object numbers seemed to line up to objects I had created.

thanks!
#3
08/30/2011 (11:15 pm)
On a few related notes,
1) Do you know where I could find a guide/link on how the overall script structure works? There is lots great info about the syntax, but I'm having trouble finding out about how the classes work together and how to use them in what situations, in a big picture kind of way. For example:
Canvas.setContent(mainScreenGui) why do we use it? How does action map fit into this and how does the level get to the main screen gui? I have problems whenever I try to get other levels (scenes) loaded.
2) script Debug. How?
3) Torque dev do you use it? the documentation seems to be dead, the forums are.

#4
08/31/2011 (1:25 am)
@David I think there was 'already in a scenegraph' warning for clones discussion, it's an engine flaw if I remember correct. You can set $pref::T2D::warnSceneOccupancy to false to disable these.


Tutorials are good to start with not because they are instruct you on how to make a game or explain everything, but because they're raising questions, and figuring out what every thing there does is where you actually learn things.

Documentation does it's job at least half of the time, maybe a bit better when you know what you are looking for. First of all you should get familiar with SimObject which is parent for all other types, and t2dSceneObject which is a parent for all objects you can have on the scene. You might find out for example that internalName and name is two different fields, or find methods you should probably use instead of accessing these fields directly, such as setEnabled(), getName() and others.

Then, you also have engine source, dumpConsoleFunctions(), common scripts as an example and a freedom to do experiments. Pretty much enough to make no assumptions on what behavior does, but read through it and figure out it's function exactly.