I had a problem with a victory system in Godot 3.5

Godot Version

Godot 3.5

Question

I had a problem with my victory system in Godot 3.5, what happened with my victory system for my game is that when I win in the game it always sends me to the first victory screen, my question is: How can I make the code in GDScript detect the screen that it should execute, for example, if it is in level 2 it should execute the victory screen of level 2? Thank you very much in advance.

You can give each level a variable that indicates what number it is, and then load the scene based on that variable.

2 Likes

Can you give me an example of how to create that code, sorry for the inconvenience, I’m a beginner at least to create that kind of systems for games in Godot 3.5.

Personally I’d use a singleton for this purpose.

You can have the current level access or signal it. You can even have a function in the singleton that will play the proper victory scene.

Edit: here is some code too

Singleton script

extends Node2D

var current_level

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass

func finish_stage():
	if current_level == 1:
		print("level 1 fanfair")
	elif current_level == 2:
		print("level 2 fanfair")

level script

extends Node2D

var this_level_is = 1

# Called when the node enters the scene tree for the first time.
func _ready():
	Singleton.current_level = this_level_is
	print(Singleton.current_level)
	Singleton.finish_stage()


You would call the finish_stage function in my example from whatever your trigger is for ending the stage.