0 votes

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 ... gettree (). Changescene.
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

in Engine by (91 points)

1 Answer

0 votes

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
by (12,290 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.