Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Yamz |
Hello, how could I create a random scene system that does this?
The scenes would represent the levels.
There must be two types of scenes; the complete and the incomplete. At first all scenes are of the incomplete type.
So there must be a function that randomly selects them.
To then press a button … call the function with the random scene and load it with … get_tree (). Change_scene.
Finally the shit scene must be removed with from the list of incomplete scenes and go to full
I have tried to do this … with the following code
var imcompletas: Array = [
"res://Scenas/One.tscn",
"res://Scenas/Two.tscn"
]
var completas: Array = [
]
func ob_escena() -> String:
randomize()
return imcompletas[int(rand_range(-1, imcompletas.size()))]
func _on_Play_pressed():
get_tree().change_scene(ob_escena())
completas.append(ob_escena())
imcompletas.erase(ob_escena())
print(completas)
print(imcompletas)
It works very well … but the problem is that when printing the complete ones I have incomplete … errors arise starting with the printing of the scene loaded with
print (ob_escena) … to know which scene was changed … the name of another scene is printed and not the name of the loaded scene … and obviously when printing the complete and incomplete scenes the same arise