Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lokigamer00 |
Is there any way to reset my program with hitting a button? (Reset deleted enemies etc)
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lokigamer00 |
Is there any way to reset my program with hitting a button? (Reset deleted enemies etc)
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"):
get_tree().reload_current_scene()
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
queue_free
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:
autoload_name.points += 1
emit_signal("died")
queue_free()
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