Error random scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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 = [
var completas: Array = [

func ob_escena() -> String:
	return imcompletas[int(rand_range(-1, imcompletas.size()))]


func _on_Play_pressed():

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

:bust_in_silhouette: Reply From: jgodfrey

In your _on_Play_pressed function, you call ob_escena 3 different times, which (potentially) returns 3 different scenes. I assume that’s not what you want.

Instead, you probably want something like this:

func _on_Play_pressed():
    var myScene = ob_escena() # get a single, random scene
    get_tree().change_scene(myScene) # change to the selected scene
    completas.append(myScene) # append the selected scene to the complete array
    imcompletas.erase(myScene) # remove the selected scene from the incomplete array