Call node with random text in it - how to do it?

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

I have used plain node to store text in different children nodes, and I’m trying to get a text from them on a roll of a dice - depending on the result of a die roll, a random line from that node will appear on the screen to the player.
So, let’s say d6 is rolled and the result is 3. The script goes to Line3 and randomly chooses one of the lines in it and show it to the player.
Here are the nodes - each Line represents possible lines from the result of a roll of a d6
here is the inspector screen from one of the lines

:bust_in_silhouette: Reply From: njamster
func _ready():

func choose_random_text():
    # choose one of the Line-nodes at random
    var id =  randi() % 6 + 1
    var line = get_node("Line" + str(id)

   # choose one of the nodes lines at random
    var random_id = randi() % line.lines.size()

worked like a charm, thanx!

badtaste988 | 2020-08-02 17:32