0 votes

Is there a way to achieve sth like this with an autowrapped label, label.get_line(3)?

PS: I have tried get_text() and then split("/n")ing it, but that didn't work.

extends Label

var text = ["test","a car is cool","Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea est Lorem ipsum dolor sit amet."]

var k = 0
var narrating = false

func _ready():
    set_text(text[k])
    set_process_input(true)
    print(get_max_lines_visible())

func _input(event):

    if Input.is_action_pressed("ui_accept") and not narrating:
        k+=1
        if k >= text.size():
            k = 0
        set_visible_characters(0)
        set_text(text[k])

    elif  Input.is_action_pressed("ui_accept") and narrating:
        set_visible_characters(text[k].length())

func _on_Timer_timeout():

    if not get_visible_characters() >= text[k].length():
        narrating = true
        set_visible_characters(get_visible_characters() + 1)
    else:   
        print(get_text().split("\n")[0]) <-- This doesn't ouput the first line, but the hole text
        narrating = false
        return

Scene structure:

http://imgur.com/a/8lwcJ

asked Sep 1, 2017 in Engine by Chain (71 points)

Please log in or register to answer this question.

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.