Godot Version
4.2.2
Question
I am out of practice by like 3 years and I’m trying to bring my old project from 3.6 to 4.2.2 to clarify I was using an edited version of the Godot Open Dialogue by jsena which this is a piece of
In 3.6 my code worked as such
func initiate(file_id, block = 'first'): # Load the whole dialogue into a variable
id = file_id
var file = File.new()
file.open('%s/%s.json' % [dialogues_folder, id], file.READ)
var json = file.get_as_text()
dialogue = JSON.parse(json).result
file.close()
first(block) # Call the first dialogue block
The variable json
gets the file as:
{
"first":
{
"type": "text",
"content": "The text isn't important",
"next": "0"
},
"0":
{
"type": "text",
"content": "Second unimportant thing"
}
}
and when it gets parsed into dialogue
it looks like this:
{0:{content:Second unimportant thing, type:text}, first:{content:The text isn't important, next:0, type:text}}
With prereq out of the way
in 4.2.2. I have code that is this
func initiate(file_id, block := 'first'):
# Load the whole dialogue into a variable
var id = file_id
var file = FileAccess.open("%s/%s.json" % [dialogues_folder, id], FileAccess.READ)
var json := file.get_as_text()
file.close()
var parse_result = JSON.parse_string(json)
dialogue = parse_result
first(block)
The variable dialogue
is outputting
{ "first": { "type": "text", "content": "The text isn't important", "next": "0" }, "0": { "type": "text", "content": "Second unimportant thing" } }
I’m getting the data but it’s in a different order (which seems to be alright? I can’t get the second screen textbox to work but I think it’s because it’s formatted different from before. If there is only one screen of dialogue it works) in 3.6 parsing it got rid of all the extra quotation marks
If I add these lines after the var dialogue = JSON.parse_string(json)
and replace the final dialogue
to take cleanJson
var cleanJson = JSON.stringify(parse_result)
cleanJson = cleanJson.replace('\"','')
cleanJson = cleanJson.replace(',',', ')
dialogue = cleanJson
dialogue
{0:{content:Second unimportant thing, type:text}, first:{content:The text isn't important, next:0, type:text}}
That “cleans up” the data but then anytime I have a quotation mark or comma in my dialogue it would get messed up. It’d work mostly but the edge cases would break it. Additionally later in the code dialogue
uses a has method so I need to keep it as a dictionary…
This all feels hacky and like I’m doing it wrong. Any help would be greatly appreciated.