0 votes

I have a text file which has something like

and i want to load it into godot as a dictionary

func load_file():
     var dictionary = {}
     var file = File.new()
     file.open("filelocation", File.read)enter code here
     dictionary = file.get_as_text().split(whenver there's a line break split)

I have something like this (im on my phone so it's not exact), but I only get an array and not a dictionary

in Engine by (33 points)

1 Answer

0 votes
Best answer

you can read a dictionary using the json file functions it has a specific format tho, which you can see by calling to_json on the dictionary

extends Control

var _data := {
    "a": "this",
    "b": "that",
    "c": "other"

func _ready():
    var json := to_json(_data)
    print(json) # read this from file and then parse it
    var dictionary : Dictionary = JSON.parse(json).result
    for key in dictionary:
by (1,667 points)
selected by
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.