I have a problem regarding resetting the game. I am working through a course and of course I soon wanted to change something and that led to some problems on of which is below. At first I couldn’t figure out why the game wouldn’t reset and following the logic I soon realized that everything was being queue_free’d not great if you want to reset the game and start over within the game. I would have to redo the course to instantiate everything, changing the course entirely, something I don’t want to do. So, I came up with something that might work. Instead of queue_free’ing the objects just make them invisible and unable to shoot/move. However, try as I might I cannot get the player tank to become visible again after it been hit and turning it invisible. It gets hit by a bullet goes invisible and on game over cannot get it to reappear. Code is as follows it’s all hacked out not much thinking or planning has gone into it:
#function called by player - when blue_tank is destroyed #probably when the reset button is hit as well
func game_over()->void:
print(“\nGame Over dude…”);
player.visible = true; #two different ways to turn tank back on
player.tank_visible(); #two different ways to turn tank back on
print("Is Player Visible here: " +str(player.player_visible) );
game_started = true;
I cannot figure out why player.visible=true; is not working. The scene tree says it’s not visible so it should be a simple case of turning it back on? Anyway. i can’t see what the problem is.
Is there a reason why when restarting the game you can’t reload the scene through get_tree().change_scene(“In here is whatever the scene file path is”) ?
Yes, there is It’s because it’s a bare_bones course like really bare bones and it has a menu system to access the games as the only real scene, and then the game in instantiated into that scene. And then things are instantiated into that scene. It’s a mess. Reloading the scene causes the game to drop back into the menu for the games, Something I am trying to avoid.
So to clarify, you only need help with getting the player visible again? If so there is a function called show() which sets the visibility to true. There could be something that is constantly setting it’s visibility to false so you might want to set things like the visibility to true after restarting the game.
I’ll try and find whatever is there is something doing that - can’t imagine that being the case but it could be hiding there in the code - considering my code is pretty helter-skelter.
Took a while to find out what was happening but it was the process function that wasn’t allowing things to become visible again . This has has thrown a lot more potential problems into the woodwork that I wasn’t anticipating, like how I would get the enemies being drawn again, placing the objects into the right place after they have moved around the playboard and how to handle the enemies after being shot.
Ok been making some progress with the “disappear” method when the enemy is hit. But when the enemy is hit after “disappear” it is still registering. So I tried this:
func _on_tank_area_area_entered(area: Area2D) -> void:
#if a nullet hits a red tank
if (area.is_in_group("bullet")):
$"..".red_tanks -= 1;
#queue_free(); #I thought the tanks had health, oh well
#and the author mentioned it as well
enemy_destroyed = true;
tank_invisible();
Autoload.stop_bullets.emit();
can_fire = false;
area.disabled = true;
#end
hoping to get arounf the collision firing again but the line:
area.disabled = true;
is giving me the error:
Invalid assignment of property or key 'disabled' with value of type 'bool' on a base object of type 'Area2D'.
And I can’t figure out why! Can anyone shine some light on the matter? Should I be turning off the collision some other way.
This error tells you there is no disabled parameter on the Area2D.
It helps to check what parameters there are on the node before you try to access and modify them. As you can see, Area2D doesn’t have a disabled parameter.