0 votes

Is there any way to reset my program with hitting a button? (Reset deleted enemies etc)

asked Jan 3 in Engine by lokigamer00 (16 points)

1 Answer

+1 vote

You can use SceneTree.reloadcurrentscene() when you want to reset the game.

For example, to reset when hitting "Escape":

func _unhandled_input(event):
    if event.is_action_pressed("ui_cancel"):
        get_tree().reload_current_scene()
answered Jan 3 by kidscancode (13,248 points)

it served me, and another query, how do I add a point to a variable when I kill an enemy with collisions?

func _on_VisibilityNotifier2D_screen_exited ():
queue_free ()

You just want to add one to a variable?

variable_name += 1

no, I want it to detect when an enemy is eliminated with

queue_free

and if it was eliminated add a point to a varieble, will I explain?

I see. But where is the variable? Without knowing that, I can think of a couple of solutions:

1) In a singleton - call it directly:

autoload_name.points += 1

2) In a "main" or "world" scene - emit a signal:

emit_signal("died")
queue_free()

Make sure that signal is connected to the main scene:

func _on_enemy_died():
    points += 1

Thanks, it worked!

And, another question, how do I make an enemy move randomly? type space invader that ships move to the right and left randomly mind

You should open a new question if you have a different topic.

I'll open it right now, go answer it

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.