Dialogue Box: Problems with mouse inputs

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

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.

:bust_in_silhouette: Reply From: flurick

Here we go, that was fun :slight_smile: 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

Thank you it worked

Lynn_Len | 2018-10-23 17:42