Topic was automatically imported from the old Question2Answer platform.
Asked By
Prestidigitator
Old Version
Published before Godot 3 was released.
Hey guys I’m working on my first complete game in the Godot Engine. I want it so that when I go in the goal (All the goals in each level(scene) is attached to one script) that it goes from Level 1.xml to Level 2.xml and Level 2.xml to Level 3.xml, and etc. So here’s how I thought I could do it;
"
#Not actual syntax
func ready():
var currentScene = get_tree().get_current_scene().get_name()
func _on_Goal_body_enter( body ):
if body.is_in_group("Player"):
if (currentScene == "res://Scenes/Levels/Level 1.xml"):
get_tree().change_scene("res://Scenes/Levels/Level 2.xml")
if (currentScene == "res://Scenes/Levels/Level 2.xml"):
get_tree().change_scene("res://Scenes/Levels/Level 3.xml")
"
Obviously that’s not the actual code, and even when the syntax was correct it didn’t work. Please Help.
func _on_Goal_body_enter( body ):
if body.is_in_group("Player"):
global.go_next_stage()
I would not put this in a singleton, because if you want to test level 10 right away, reaching the end would teleport you to level 2 unless you set the number in the global somehow.
Anyways I avoid singletons for the same reason I avoid global static things in any program
What I do instead is to have a next_level property inside my level_end object in the level, so choosing what is next is easier and doesn’t requires a naming convention. So when you test any level, the game can continue as normal.
As a little bonus, it also allows a level to have multiple endings. But maybe you won’t need it