Asteroids Tutorial Problem
by Do Not Delete · in Torque Game Builder · 07/27/2008 (1:03 pm) · 11 replies
I'm following the asteroids tutorial to make a simple game but I'm having some problems.
1. The score keeps adding when my player is alive even though I don't hit anything.
2. After I destroy all the small asteroids, new ones don't spawn.
I've tried many times to follow the tutorial. I do everything step by step but, I'm still having those problems.
Also I want to implement the following into my game but I don't know how.
1. How can I add a simple pause screen when the user presses escape? I know how to make a gui screen but I don't know how to pause the game when the user presses escape.
2. How can I make the game end and go back to the main menu screen after I get a game over (when you loose all 5 lives)?
Can anyone please help?
Thanks,
Dro Sarhadian
1. The score keeps adding when my player is alive even though I don't hit anything.
2. After I destroy all the small asteroids, new ones don't spawn.
I've tried many times to follow the tutorial. I do everything step by step but, I'm still having those problems.
Also I want to implement the following into my game but I don't know how.
1. How can I add a simple pause screen when the user presses escape? I know how to make a gui screen but I don't know how to pause the game when the user presses escape.
2. How can I make the game end and go back to the main menu screen after I get a game over (when you loose all 5 lives)?
Can anyone please help?
Thanks,
Dro Sarhadian
About the author
#2
$timeScale = 0.0;
// Back to main menu
Canvas.setContent(mainMenuGui); // or whatever you called it
I don't know any specifics about the Asteroids tutorial (didn't know there was one), so I don't know exactly where you want to check if there are no lives left, or what the variable is called...
07/28/2008 (11:41 am)
// Pause the game$timeScale = 0.0;
// Back to main menu
Canvas.setContent(mainMenuGui); // or whatever you called it
I don't know any specifics about the Asteroids tutorial (didn't know there was one), so I don't know exactly where you want to check if there are no lives left, or what the variable is called...
#3
07/28/2008 (11:47 am)
Okay, I got it to go back to the main menu, but when I play the game again, I can't control the ship and no enemies spawn.
#4
07/28/2008 (11:55 am)
You probably want to end the level and reload it, so everything starts from a clean slate the second time around. Look at t2dSceneWindow methods for doing this.
#5
What code do I need to add?
Also, how can I get the game to show the pause screen only when I'm in the level, because right now I can pause the game inside the main menu.
07/28/2008 (12:05 pm)
I can't find what I'm looking for. Right now, when I click the new game button it calls the startNewGame function and in that function is 1 line of code. function startNewGame()
{
startGame(expandFilename("game/data/levels/battleground.t2d"));
}What code do I need to add?
Also, how can I get the game to show the pause screen only when I'm in the level, because right now I can pause the game inside the main menu.
#6
Open up the reference documentation and figure it out, or if you are using Torsion look in the codebrowser.
07/28/2008 (12:11 pm)
Theres a whole slew of level related methods in t2dSceneWindow and t2dSceneGraph, I don't remember what they all are or which you need to use. Looking around the game scripts is good to do, but a lot of the TGB class methods are not defined in a script file, there are exposed from C++.Open up the reference documentation and figure it out, or if you are using Torsion look in the codebrowser.
#7
07/28/2008 (1:56 pm)
Alright, I'll have a look again. Also is it possible for me to release a game I make with the trial of TGB for free?
#8
04/28/2009 (9:53 am)
I'm having this same problem was there ever any solution?
#9
Technically, if you have created your scene properly it should work.
Basically, it gets the current sceneGraph and then checks to make sure it is valid. Next, it clears the current scene of all objects and deletes the objects. Finally, you load your new scene or the scene you want to start over with.
I don't know if this will work, because I haven't tried it. However, in theory it should work.
04/28/2009 (11:20 am)
My Recommendation for setting a new game up:%scenegraph = sceneWindow2D.t2dSceneWindow.getSceneGraph();
if(isObject(%scenegraph))
{
%scenegraph.clearScene();
%scenegraph.loadScene("scenewhatever.t2d"); //replace with the correct scene name
}Technically, if you have created your scene properly it should work.
Basically, it gets the current sceneGraph and then checks to make sure it is valid. Next, it clears the current scene of all objects and deletes the objects. Finally, you load your new scene or the scene you want to start over with.
I don't know if this will work, because I haven't tried it. However, in theory it should work.
#10
I cannot track down the exact source of that issue to save my life. It seems to be connected to this error I receive in my console every time it spawns an asteroid:
t2dSceneGraph::addToScene() - Object '1437' is already in a SceneGraph!.
(Object number changes every error)
It would appear that this is located within the SpawnArea behavior as well, so if anyone could connect the dots for me I would greatly appreciate it.
Edit: I have found out that the error in my console is normal and how to fix the score problem easily.
The reason the score goes up every time an asteroid is spawned is because when it first spawns it for some reason immediately calles the RemovedFromScene function. To fix this you just have to make a small edit to the "scorePoint" behavior script.
Find the RemoveFromScene function in that script, and add the following code right at the beginning of it:
if(!%this.scoreEnabled){
%this.scoreEnabled = 1;
return;
}
Your new function should look like:
function ScorePointsBehavior::onRemoveFromScene(%this, %scenegraph){
if(!%this.scoreEnabled){
%this.scoreEnabled = 1;
return;
}
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;
$currentScore = $currentScore + %this.pointValue;
echo("Updating Score");
%counter.updateScore();
}
What this does is checks to see if %this.scoreEnabled is equal to 1, if not it makes it so and terminates the function. This means that the function must be called once to initiate it before it does anything, which the objects do when they spawn.
Your scoring problem should now be fixed :)
Note: Really, I think this is more of a problem caused by using the behaviors. It appears that sometimes it will not register an error and try to remove the object so the hack I made then stops it from registering an actual death. I'd suggest scripting the spawning system.
05/19/2009 (10:03 pm)
I am now experiencing the same problems expressed in the OP.I cannot track down the exact source of that issue to save my life. It seems to be connected to this error I receive in my console every time it spawns an asteroid:
t2dSceneGraph::addToScene() - Object '1437' is already in a SceneGraph!.
(Object number changes every error)
It would appear that this is located within the SpawnArea behavior as well, so if anyone could connect the dots for me I would greatly appreciate it.
Edit: I have found out that the error in my console is normal and how to fix the score problem easily.
The reason the score goes up every time an asteroid is spawned is because when it first spawns it for some reason immediately calles the RemovedFromScene function. To fix this you just have to make a small edit to the "scorePoint" behavior script.
Find the RemoveFromScene function in that script, and add the following code right at the beginning of it:
if(!%this.scoreEnabled){
%this.scoreEnabled = 1;
return;
}
Your new function should look like:
function ScorePointsBehavior::onRemoveFromScene(%this, %scenegraph){
if(!%this.scoreEnabled){
%this.scoreEnabled = 1;
return;
}
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;
$currentScore = $currentScore + %this.pointValue;
echo("Updating Score");
%counter.updateScore();
}
What this does is checks to see if %this.scoreEnabled is equal to 1, if not it makes it so and terminates the function. This means that the function must be called once to initiate it before it does anything, which the objects do when they spawn.
Your scoring problem should now be fixed :)
Note: Really, I think this is more of a problem caused by using the behaviors. It appears that sometimes it will not register an error and try to remove the object so the hack I made then stops it from registering an actual death. I'd suggest scripting the spawning system.
#11
The shooter engine uses CLASS like:
PlayerShip
EnemyShip
and I have created the TEXT Object without a class with only the name: scoreObject using the behavior displayScore and also I have set the EnemyShips with the ScorePoints behavior with the counter on scoreObject.
But nothing happens...
if I set the function to:
function ScorePointsBehavior::explode(%this){
if(!%this.scoreEnabled){
%this.scoreEnabled = 1;
return;
}
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;
$currentScore = $currentScore + %this.pointValue;
echo("Updating Score");
%counter.updateScore();
}
I receive points hitting my EnemyShips, but they don´t destroy(they keep invincible)
could you guys give me a help here?
07/30/2009 (3:14 pm)
I tried to use the behaviors displayScore and ScorePoints with the shooter engine but as I have put 5 enemies on my game, at the very start of my game without doing nothing it appears SCORE : 50 and as I start killing spawning enemies I get no points.What could that be?The shooter engine uses CLASS like:
PlayerShip
EnemyShip
and I have created the TEXT Object without a class with only the name: scoreObject using the behavior displayScore and also I have set the EnemyShips with the ScorePoints behavior with the counter on scoreObject.
But nothing happens...
if I set the function to:
function ScorePointsBehavior::explode(%this){
if(!%this.scoreEnabled){
%this.scoreEnabled = 1;
return;
}
%counter = %this.counter.getBehavior("DisplayScoreBehavior");
if (!isObject(%counter))
return;
$currentScore = $currentScore + %this.pointValue;
echo("Updating Score");
%counter.updateScore();
}
I receive points hitting my EnemyShips, but they don´t destroy(they keep invincible)
could you guys give me a help here?
Torque Owner Do Not Delete