+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

asked Nov 16, 2019 in Engine by hsn (43 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)

answered Nov 20, 2019 by hsn (43 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.