Looks like you're not logged in

Login or Register to continue

Lesson Q&A

Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.

  • My simple dialogue systemPurpleSunriseHello, I wanted to share my dialogue system. It's much simpler than the reference. Do you think it's valid? Is it too simple or error prone? I created a resource: ```gdscript class_name DialogueItem extends Resource @export var emotion : Texture2D = null @export var portrait : Texture2D = null @export_multiline var text : String = "" ``` I created a UI scene for the dialogue box: ```gdscript class_name DialogueBox extends Control signal dialogue_finished @onready var next_button: Button = %NextButton @onready var text_label: Label = %TextLabel @onready var npc_portrait: TextureRect = %NpcPortrait @onready var npc_expression: TextureRect = %NpcExpression @export var npc_dialogue : Array[DialogueItem] = [] var dialogue_idx : int = 0 func _ready() -> void: hide() next_button.pressed.connect(func()->void: display_textbox(dialogue_idx) ) func _input(event: InputEvent) -> void: if event.is_action_pressed("interact") and next_button.disabled == false and visible == true: next_button.emit_signal("pressed") func display_textbox(index : int)->void: if index == npc_dialogue.size(): hide() emit_signal("dialogue_finished") return show() next_button.disabled = true text_label.text = npc_dialogue[index].text npc_portrait.texture = npc_dialogue[index].portrait npc_expression.texture = npc_dialogue[index].emotion text_label.visible_ratio = 0.0 var printing_time := text_label.text.length() / 20.0 var tween := create_tween() tween.tween_property(text_label,"visible_ratio", 1.0, printing_time) await tween.finished dialogue_idx += 1 next_button.disabled = false ``` Then I created a scene for Sophia NPC: ```gdscript class_name Npc extends StaticBody2D @onready var area_2d: Area2D = %Area2D @onready var dialogue_box: DialogueBox = %DialogueBox @export var dialogue : Array[DialogueItem] = [] var _player : Player = null func _ready() -> void: dialogue_box.npc_dialogue = dialogue dialogue_box.dialogue_finished.connect(func()->void: if _player != null: _player.remove_control_from_player(false) set_process_unhandled_input(true) await get_tree().create_timer(0.2).timeout dialogue_box.dialogue_idx = 0 ) area_2d.body_entered.connect(func(body : Node)->void: if body is Player: _player = body) area_2d.body_exited.connect(func(body : Node)->void: if body is Player: _player = null) func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("interact") and _player != null: set_process_unhandled_input(false) _player.remove_control_from_player(true) dialogue_box.display_textbox(dialogue_box.dialogue_idx) ``` Is this too simple? Also I created a timer to let the dialogue box close before resetting the index. Is it bad way to do this? I didn't add sliding tweens etc but I think it wouldn't be a problem to add those features to this script right? Thank you in advance! It was pretty fun! 3 0 Feb. 03, 2025
  • Code addition and one little issuePixAngelIf the player decides to leave after the conversation and then come back, I can't see in your code that the array is reset. Below it's how I solved it for me : ```gdscript func _ready() -> void: dialogue() _next_button.pressed.connect(func()-> void: dialogue_index += 1 if dialogue_index == dialogue_item.size(): dialogue_index = 0 dialogue() EndDialogue.emit() else: dialogue() ) ``` Another issue is tweens effect are already read before talking to NPC for the first time. How to delay the reading of these tween knowing that the cause comes from the ready function. Can we instantiate the dialogue.tscn in a another way to solve it, or does it exist a method to delay tween effect? 3 0 Jan. 24, 2025
  • Error when showing the dialogue with the NPCram876Hello! I'm stuck at the stage where I need to bring up the NPC dialog box. The dialog itself works without errors, but when I start the dialog, I get an error that the dialog nodes do not exist. Here is my project. In my project, I used resources. 3 0 Jan. 11, 2025
  • can you solve this particle issue?Celsthe particles emit immediately when the scene starts even though that particle in inspectator is set to be false? is that bug in godot? 3 0 Jan. 01, 2025
Site is in BETA!found a bug?