I am making a visual-novel style game with a JSON dialogue system that allows for branching. My branching dialogue choice buttons are on a CanvasLayer in a VBoxContainer, and are regular buttons. In most of my scenes it works fine. I have a scene where there are two different instances of dialogue, and the branch occurs on the second. In this one, for some reason, no matter what I do, the CanvasLayer containing the choice buttons won’t change visibility until after it’s clicked. I have it hidden by default in the Scene Dock, hidden (and shown at the correct time) manually in the code, and have tried only one or the other. But it simply will not hide, appearing for the entirety of the scene until it is clicked. It still triggers the correct dialogue when clicked, but obviously it should wait for the correct moment to do so.
In researching I have only found solutions for the inverse issue (CanvasLayer will not appear). Has anyone encountered this version of the issue before? Thank you for any help! Happy to provide code/screenshots.
Since it’s a JSON-based dialogue system, I have it set up so that this is the code displaying the JSON file on a block-by-block basis. The main code (with some irrelevant initializations and input handling omitted, the relevant parts are the part relating to “choices”):
@export_file("*.json") var jsonsrc
@export var choicelayer : CanvasLayer
func _ready() -> void:
get_json(jsonsrc)
load_block(current_block)
# parse json file as dict
func get_json(src: String):
var jsontext = FileAccess.get_file_as_string(src)
scene_script = JSON.parse_string(jsontext)
current_block = scene_script["start"]
# update state to show contents
func load_block(block : Dictionary):
if block.has("name"): name_label.text = block["name"]
if block.has("date_time"): date_time.text = block["date_time"]
if block.has("text"): char_text.text = block["text"]
char_text.visible_ratio = 0.0
var char_raw = str(char_text.text)
tween = create_tween()
tween.tween_property(char_text, "visible_characters", len(char_raw), len(char_raw) * CHAR_READ_RATE)
if block.has("message_color"): box_bg.set_color(block["message_color"])
# if block.has("sfx"): sfxplayer.play_sound(block["active_sound"])
if block.has("choices"):
choicelayer.show()
choicelayer.set_choices(block["choices"])
if block.has("next"):
var key = block["next"]
next_block = scene_script[key]
pass
# load next block for display
func next():
current_block = next_block
load_block(current_block)
pass
func _on_choices_next_id(id: String) -> void:
next_block = scene_script[id]
next()
choicelayer.hide()
pass
And then in the CanvasLayer displaying the choices:
extends CanvasLayer
@export var signchoices : ButtonGroup
var dialogue_choices : Dictionary
signal next_id(id: String)
func _ready() -> void:
signchoices.pressed.connect(get_choice)
func set_choices(choices: Dictionary):
dialogue_choices = choices
var index = 0
var buttons = signchoices.get_buttons()
for c in choices.keys():
buttons[index].text = c
index += 1
func get_choice(b: Button):
var id = dialogue_choices[b.text]
next_id.emit(id)
pass
I have checked that everything is properly connected; no resource paths have been accidentally changed or the like.
my two cents is that you seem to cling to JSON as if its important what serialization format you use. It’s just a format. You can serialize your dialogue data in binary with the same effect. What you want is a proper editor for your dialogue data, so you dont have to care what format the data is stored in.
I’m very new to all this, but I’m familiar enough with JSON file format and have grown familiar with using it in Godot to manage the entirety of my dialogue system including sprites and triggering scene transitions. What would you recommend I do to get this to work, in this case? Would it be best to go about it in another way? And how does this impact the CanvasLayer visibility issue?