The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I've tried both node and control as the extends. Can anyone tell my why it seems file_exists doesn't seem to be there at all.

extends Node

onready var file = File.new()

func load_data(url) -> Dictionary:
if url == null: return {}
if !file.file_exists(url): return {}
file.open(url, File.READ)
var data:Dictionary = {}
data = parse_json(file.get_as_text())
file.close()
return data

func write_data(url:String, dict:Dictionary):
if url == null: return
file.open(url, File.WRITE)
file.store_line(to_json(dict))
file.close()
in Engine by (60 points)

more info... I was originally tryiing to pass in a .bin file as the url. I don't know if that matters. The .bin file isn't seen by godot's filesystem. I've tried changing it to a .txt and a .dat nothing seems to take with 3.1. But the error seems to be with file not seeing fileexists anywhere not the filestring passed into it. Seems like if it was seeing fileexists it would just say false for not being able to see the file.

working code

extends Control

#onready var file = File.new()

func load_data(url) -> Dictionary:
var file = File.new()
if url == null: return {}
if !file.file_exists(url): return {}
file.open(url, File.READ)
var data:Dictionary = {}
data = parse_json(file.get_as_text())
file.close()
return data

func write_data(url:String, dict:Dictionary):
var file = File.new()
if url == null: return
file.open(url, File.WRITE)
file.store_line(to_json(dict))
file.close()

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.