+1 vote

Hi guys

I am creating a function which gets the coordinates of puzzle pieces and store them in a json file. The problem is, its only saving one entry and is not appending the entries into file.
Related code is below :

if event is InputEventMouseButton and !event.pressed:
var eventpos = getposition()
var pid = id
tofile(eventpos, id)

func writetofile(pos, pid):
print(pos, p

var event_data = {}
var data_files = File.new()
if data_files.open(global.Event_FILE_PATH, File.WRITE) != OK:
event_data["Position"] = pos
event_data["Piece_ID"] = p_id

in Engine by (45 points)

I'm pretty new to Godot/json, but afaik If eventdata["Position"] and eventdata["Place_ID"] are lists:


Putting Position and ID into arrays, anyhow its solved and thanks alot for your answer.

1 Answer

0 votes
Best answer

I have solved the problem as follows and its working fine now , however if needed I can share the full code for Writetofile function

if datafile.fileexists(global.EventFILEPATH): datafile.open(global.EventFILEPATH, File.READWRITE)
else: datafile.open(global.EventFILE_PATH, File.WRITE)

by (45 points)
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.