0 votes

After the game over screen appears you have two buttons. One goes to main menu, Another restarts the game.

This is my GUI Scene
enter image description here
What Scene looks like with gameover menu
enter image description here

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.

in Engine by (51 points)

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.