0 votes
func _ready() -> void:
    $ScoreCount.text = str(Globals.Score) 
    set_process(true)
    spawn_Player1(1)
    for i in range(4 + Globals.Score): 
        spawn_Enemy1()

func spawn_Player1(num):
    for i1 in range(num):
        var p1 = player1.instance()
        p1.connect("Player1_pressed", self, "_on_Player1_pressed")
        Player_container1.add_child(p1)


func _on_Player1_pressed():
    if Globals.timeLeft > 0:
        Globals.timeLeft += 5
        if Globals.timeLeft > Globals.maxTime:
            Globals.timeLeft = Globals.maxTime
    Globals.Score += 1
    get_tree().change_scene("res://Game.tscn")

func spawn_Enemy1():
    var rand1 = floor(rand_range(0, Enemy1.size()))
    var piece1 = Enemy1[rand1].instance()
    add_child(piece1)

This is my Main Scene Code.

I want that when the onPlayer1_ pressed event happens that the Scene doesn't start right away, it should wait like 2 seconds before load to the next Scene (i tried some things with the Timer Node). And if the onPlayer1_ pressed event happends and the Waittime is set, i want it that the Player Freezes and Enemies are not visible for the duration of the Waittime. And it should not register Score more than 1 time for each Scene.

Thank you in advance for AndyCampbell and jgodfrey :/ i still wait for the Random Functions solution, i sent the code on a comment there.

in Engine by (133 points)

1 Answer

+1 vote
Best answer

For the main question (delay scene load for 2 seconds), you can just add something like this to your existing function:

func _on_Player1_pressed():
    if Globals.timeLeft > 0:
        Globals.timeLeft += 5
        if Globals.timeLeft > Globals.maxTime:
            Globals.timeLeft = Globals.maxTime
    Globals.Score += 1
    yield(get_tree().create_timer(2.0), "timeout") // <--- Add this
    get_tree().change_scene("res://Game.tscn")

That'll dynamically create a timer, set it to run for 2.0 seconds, and wait for its timeout signal to fire before executing the remaining code (the scene change).

For your other questions, I'd recommend you ask them separately rather than include them as part of this one...

by (10,928 points)
selected by
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 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 webmaster@godotengine.org with your username.