Godot 4.7
What is a god way to make a next level button wich works in all levels?
I know I can just make a:
button_pressed()
signal that calls:
get_tree().change_scene_to_file("res://my/spcific/level")
But then I have to make a separate script for every level, which doesn’t seem like a good solution to me.
Is there a better way to do this? Maybe using an array or something similar?
Thanks for reading!
@export var next_level: PackedScene
get_tree().change_scene_to_packed(next_level)
Make a scene that lets you switch levels, and re-use it. The only unique thing about the scenario you describe is what scene to link to next. You can capture that with a string like so:
@export_file("*.tscn") var next_level : str = ""
Okay can you show me a better example of waht you men(i am kinda new to coding)?
For example how to make the string part of the file path?
Okay so i have to write the level name to the export thing in the inspector.
Just make a new scene like you normally would, extending it from base class Button. Then add a new script and add the level switching logic. Save the scene, then add an instance of it in your level (or wherever it should go.)
Or click on the field to open a file dialogue that lets you select a scene to link.