Welcome to OStack Knowledge Sharing 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...