Game Development Community

troubles with 'displayScore' in Asteroids tutorials

by David Chutka · in Torque Game Builder · 07/14/2009 (8:25 am) · 6 replies

Hello all,

As usual, this is probably a very simple solution that is right in front of me and I just don't see it, but I'm currently working through the Asteroids tutorial. When it comes to writing all the scripts I type it all out instead of copying and pasting. Usually when I have an issue it is directly related to me having some sort of typo in one of the scripts. However, this time I don't think that is the case.

I am to the point where I have to set up the displayScore behavior and everything appears to be typed properly. I have it pasted below:

if (!isObject(DisplayScoreBehavior))
{
%template.friendlyName = "Display Score";
%template.behaviorType = "GUI";
%template.description = "Allows a text object to display the score";
}

function DisplayScoreBehavior::onAddToScene(%this, %scenegraph)
{

function DisplayScoreBehavior::onAddToScene(%this, %scenegraph)
{
$currentScore = 0;
%this.owner.text = "Score:" SPC $currentScore;
}

function DisplayScoreBehavior::updateScore(%this)
{
%this.owner.text = "Score:" Spc $currentScore;
}


What I see in TGB is different though. When I go to the behaviors list and try to add it to the text object that I added to the game it has the default GUI behaviors listed in the window. Things like "hoverImage", "hoverFrame", "clickImage" and things along those lines. On top of that, if I just add the behavior anyway and try to run the game it doesn't keep track of the score.

Where did I go wrong? Any clues? The other interesting thing is that in my behaviors folder there isn't a displayScore.dso. Every other .cs file has a .dso file to accompany it. I don't know what the dso file is, i just know that the displayScore.cs doesn't have one.

Any guesses? As always, the help is greatly appreciated.

#1
07/14/2009 (10:31 am)
function DisplayScoreBehavior::onAddToScene(%this, %scenegraph)
{


you are missing your end bracket

EDIT:

actually... remove that first onAddToScene.

function DisplayScoreBehavior::onAddToScene(%this, %scenegraph)
{

function DisplayScoreBehavior::onAddToScene(%this, %scenegraph)
{
$currentScore = 0;
%this.owner.text = "Score:" SPC $currentScore;
}
#2
07/14/2009 (11:11 am)
Good news and bad news. It now has that .dso file, so things are moving in the right direction. However, the same issues still exist as far as how it appears in TGB and the lack of any score in the actual game. I have even gone back and just copied and pasted the text in the tutorial to make sure it wasn't me missing something.

Thanks for the partial success. I will have to continue to investigate once i return in a while. It has to be something simple that I'm just missing somewhere.
#3
07/14/2009 (12:28 pm)
the .dso file is just a compiled .cs file, when you go to release your game you will remove the .cs files and leave just the .dso files so people don't have access to your source code.

what exactly is happening, is the score being set at all? even to 0 or is it just saying "Score: " and thats it? what function are you changing your current score variable?
#4
07/14/2009 (1:05 pm)
can you post your scorepoint.cs code also
#5
07/14/2009 (1:35 pm)
it is just saying "Score:". here is the scorepoint.cs code. And again, this time I tried to just copy and paste to make sure it wasn't me making some stupid typing mistake. It has the exact same issue as when i had it all typed out, so I don't believe it is me. That being said, it most likely is.

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

EDIT: scratch all of that. Even though I swore i reloaded my project a few times, now that I'm home again and tried it things are working. Sort of. For some reason it keeps adding points every second or two, but that I will look into. The fact that it is at least closer to working thrills me.

Thanks for looking at this. I look forward to the day that I can answer other people's questions. I think that is about the only way to return the favor.

function ScorePointsBehavior::onRemoveFromScene(%this, %scenegraph)
{
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;

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

#6
07/14/2009 (1:49 pm)
well sounds like you are on the right track. Let me know if you can't figure out your next issue =)