How do i get this to reset every time a scene changes?

Godot Version

4

Question

var has_apple = false

var apples_to_collect: int = 5# or ideally count the apples dynamically at the start of the game
var apples_collected: int = 0

func register_apple() -> void:
	apples_collected += 1
	if apples_collected >= apples_to_collect:
		get_tree().change_scene_to_file("res://1st level victory.tscn")

right now the way it is, if you exit the level then come back, it wont reset the amount of apples collected to 0.

This must be a global then right? You could reset the apples_collected directly before changing scenes.

func register_apple() -> void:
	apples_collected += 1
	if apples_collected >= apples_to_collect:
		apples_collected = 0
		get_tree().change_scene_to_file("res://1st level victory.tscn")
1 Like

Perfect! thank you!