Godot Version
4.1.3
Question
Oki. Following problem.
I am trying to create a small dialogue system. Therefor I started watching a YouTube Tutorial on how to, but the problem is, it uses following piece of code:
var file = File.new()
But my Godot gives me following error message: Identifier "File" not declared in the current scope
So started googling and reading the docs and I found the FileAccess
class.
Here is my code:
extends Control
var FILE_PATH = "res://dialogues/intro.json"
func _ready():
var json = JSON.new()
var file = FileAccess.open(FILE_PATH, FileAccess.READ)
var json_text = JSON.stringify(file.get_as_text(), "\t")
file.close()
var error = json.parse(json_text)
if error == OK:
var data_received = json.data
if typeof(data_received) == TYPE_ARRAY:
print(data_received)
else:
print("Unexpected Data")
else:
print("JSON Prase Error: ", json.get_error_message(), " in ", json_text)
And here is the json file:
[
{
"name": "test",
"text": "This is a test message"
}
]
normaly I would expect the json to be printed (According to the JSON Class documentation.
But instead I am getting the Unexpected Data String.
Where is the problem, and am I able to solve it?
Thanks in advance!