question i need help

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lokigamer00

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

:bust_in_silhouette: Reply From: kidscancode

You can use SceneTree.reload_current_scene() 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"):

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 ()

lokigamer00 | 2020-01-03 21:28

You just want to add one to a variable?

variable_name += 1

kidscancode | 2020-01-03 21:49

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


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

lokigamer00 | 2020-01-03 23:44

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
  1. In a “main” or “world” scene - emit a signal:

Make sure that signal is connected to the main scene:

func _on_enemy_died():
    points += 1

kidscancode | 2020-01-03 23:50

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

lokigamer00 | 2020-01-03 23:53

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

kidscancode | 2020-01-03 23:55

I’ll open it right now, go answer it

lokigamer00 | 2020-01-03 23:58