+3 votes

Hi all,

I know there are already scripts and plug ins out there that I can use but I would like to try and write my own simple dialog scene that I can re-use. Better for learning and all.

I was just hoping for some guidance and ideas that I can plug away at.

I currently have this idea happening:

extends RichTextLabel

var textToAdd

func _ready():
    textToAdd = "This is a lot of text that we can play with. This is a lot of text that we can play with. This is a lot of text that we can play with.  I'll try a new line\nand see which it is and we'll use this text as an EXAMPLE!  May we win and win well.  I'm just going to add a lot more text to handle "
    printText(textToAdd)

func printText(text):

    #create a timer to print text like a typewriter
    var t = Timer.new()
    t.set_wait_time(.005)
    t.set_one_shot(true)
    self.add_child(t)

    for letter in text:
        t.start()
        self.add_text(letter)
        yield(t, "timeout")

It works really well, the text just spits out at a steady rate.

The things I want it to do include:

1; Typing out the text like a typewriter. One letter at a time, at variable speeds.

2: Stopping when it hits the limits of the RichTextLabel so the user has to tap to continue loading the next part of text.

3: Typing out the next part of text which is not visible yet, when tapped (from step 1)

4: If tapped whilst it's typing out, it should insta draw the whole text up to the capacity of the RichTextLabel.

5: It should move onto the next part of the conversation when tapped.

6: Should allow Y/N type buttons with custom text

7: Should allow text input (for example, "What's your name?")

So I've set myself those goals. I've got step #1 finished. Easy part right.
What I'm not challenged by are the rest of the steps!

For example, ideas I have:
Step 2: Should I be counting the total available spaces in the RichTextLabel and then counting how far in I am?

Step 3: Erase contents of RichTextLabel mid way through array, then continue with array?

Step 4: If I'm drawing like a typewriter and tap, I'm guessing my loop should be looking for a variable, say called tapped. If it sees that, ignore the typewriter effect and continue with a straight dump of the array?

Step 5: This could be a whole new translated piece of text in a CSV for example. Would I reference a new KEY when the last one is finished? If so, how would I go about telling it which order to load the KEYS in?

Step 6: I guess these would just be Boolean toggles, turning them on and off with name variables. I don't think this will be too hard.

Step 7: I'm guessing same as Step 6. Turn it on, read it's data and send to wherever is required.

So, I hope someone is ok to have a discussion on these things with me? I'd love to hear ideas. I've never done this before. I'm happy to code away and experiment but I am tight on time in life (work kids, job etc) and any nudges in a better direction are always welcome. Thanks a tonne...

in Engine by (810 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.
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.

Categories