Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

load - How can I use loaded json data correctly?

So if have a variable clicks = 0 and a dict data = {"clicks": 0},

I change the clicks variable to 4 and then save it to my json file as a dict so data["clicks"] = clicks.

Later I want to reload the program and want to work with my clicks variable but it is now 0 again.

I have to load the stored value from the dict and assign it to clicks variable? clicks = data["clicks"] or I can use directly the data from the file and work with it? example: sum = data["clicks"] + 5 will be 9. this is not looking good

It is efficient? I mean opening and closing the file that stores the data and working with it as a variable. Maybe saving 2 or more variables and working with them add and subtract them etc..? but then the normal variables in the program wont be used.

The whole saving data and loading it back again to work with the values are very cloudy for me. I searched every website for an answer but I still dont know how to properly use loaded data so I can use it as a variable again, without opening and closing / saving or loading the file every "frame"(Im in a progress of making an idle like game and i need to store a lot of variables(levels, upgrades, building costs etc and working with them later) I use godot).

question from:https://stackoverflow.com/questions/65945675/how-can-i-use-loaded-json-data-correctly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...