0 votes

I'm trying to make a dating sim and I am currently working on dialogue boxes. When I click with the left mouse button after all of the text in a string has been written it will move to the next string to write; but I also want use the same mouse click to instantly write all of the string at once. Because I'm using the same mouse input to do two different things. I have tried to use a Boolean variable (called isDone) to differentiate the two mouse inputs but it's complicated things because the moment the isDone variable become true I can't turn it false again.

    #DialogueBoxs.gd
extends RichTextLabel

var dialog = ["Hello and goodbye", "HELLO, GOODBYE!", "Now I say goodbye and you say hello"]
var page = 0

var isDone = false

func _ready():
    set_bbcode(dialog[page])
    set_visible_characters(0)
    set_process_input(true)

func _input(event):
    if event is InputEventMouseButton:
        if (isDone):
            if get_visible_characters() > get_total_character_count():
                if page < dialog.size()-1:
                    page += 1
                    set_bbcode(dialog[page])
                    set_visible_characters(0)
                    isDone == false
        if !(isDone):
            if get_visible_characters() < get_total_character_count():
                set_visible_characters(get_total_character_count())
                print("False")
    if get_visible_characters() == get_total_character_count():
        isDone = true
func _on_Timer_timeout():
    set_visible_characters(get_visible_characters() + 1)

Could someone tell me how to make this work.

asked Oct 23, 2018 in Projects by Lynn_Len (41 points)

1 Answer

0 votes

Here we go, that was fun :) Mouse button down and up are two events so it would trigger twice per click. The timer did not check if it was done when progressing. Most variables you can get without the get_...() making for some shorter code.

extends RichTextLabel

var dialog = ["Hello and goodbye.", "HELLO, GOODBYE!", "Now I say goodbye and you say hello."]
var page = 0

var isDone = false

func _ready():
    set_bbcode(dialog[page])
    set_visible_characters(0)
    set_process_input(true)


func _input(event):

    if event is InputEventMouseButton and event.pressed:

        if isDone:
            if page < dialog.size()-1:
                page += 1
                bbcode_text = dialog[page]
                visible_characters = 0
                isDone = false
        else:
            visible_characters = get_total_character_count()
            isDone = true


func _on_Timer_timeout():

    if visible_characters < get_total_character_count():
        visible_characters += 1
        if visible_characters == get_total_character_count():
            isDone = true
answered Oct 23, 2018 by flurick (888 points)

Thank you it worked

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.