Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Archtects |
After the game over screen appears you have two buttons. One goes to main menu, Another restarts the game.
This is my GUI Scene
What Scene looks like with gameover menu
Everything is hidden so _ready shows the MainMenu
onready var MainMenu
onready var Overlay
onready var PlayPause
onready var GameVars
var gamestart = true
func _ready():
gamestart()
func gamestart():
if (gamestart == true):
MainMenu = get_node("/root/Main/GUI/MainMenu")
Overlay = get_node("/root/Main/GUI/Overlay")
MainMenu.show()
Overlay.show()
get_tree().paused = true
print("true")
elif(gamestart == false):
PlayPause = get_node("/root/Main/GUI/Pause/PausePlay")
GameVars = get_node("/root/Main/GUI/Game")
PlayPause.show()
GameVars.show()
get_tree().paused = false
print("false")
The on ready works fine. It shows the nodes perfectly. Everything works fine on first run. However when i activate the button pressed code:
func _on_Restart_button_down():
get_tree().reload_current_scene()
global.gamestart = false
global.score = 0
global.lives = 3
global.gamestart()
func _on_MainMenu_button_down():
get_tree().reload_current_scene()
global.gamestart = true
global.score = 0
global.lives = 3
global.gamestart()
So hit restart or Return to main menu, It refreshes the scene. But seems to ignore the $node.show() or hides?
What am i doing wrong?
Why after get_tree().reload_current_scene()
Does it seem to ignore trying to show()
nodes? Thank you.
Have you tried moving the get_tree().reload_current_scene()
to be the last line in those functions? I’m not sure, but perhaps calling reload_current_scene
stops execution (i.e. doesn’t return) since the node the script is attached to doesn’t exist any more when the scene is reloaded.
markopolo | 2018-10-06 00:50