Load Random Scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rayu

var Players = [
preload(“res://Player1.gd”),
preload(“res://Player2.gd”),
preload(“res://Player3.gd”),
preload(“res://Player4.gd”)
]

So i have made this array with 4 Scenes, and i want that only one of them is choosen randomly

please help. :confused:

:bust_in_silhouette: Reply From: Ertain

Here, I’ll give you a freebie. :wink: Try this function on for size.

# Based on the "random.choice()" function found in Python.
func random_choice(list: Array):
    if list.empty():
        push_error("Size of array is zero.")
        return
    return list[ randi() % list.size() ]

Pass your array to this function and it’ll choose a random element.

var player = random_choice(Players)