How is this done?

Hi!

How do you think that the data in stored in games like cookie clicker and make it rain?

  1. How does the game know how far you are in upgrading a certain section
  2. How does it save all the data like upgrades and cookies.
  3. (would just be nice to know) How frequently is games like this saving the data? I mean you will get more cookies or money or whatever in seconds so i guess that would cause some memory…

Thanks!

SQLite, perhaps? Or any mechanism really. Perhaps they read in the data from a file of some sort and store it in an object. When changes to the games data happen it updates variables in this class andwrites it back out to the config on some interval that makes sense.

1 Like

But of they are saving the data like every second wouldn’t that cause the game to lag maybe?

why every second ?
you save the data in memory , when the game go’s to background or in active
you can see the states here in the file :
proj.ios_mac\ios\AppController.mm
also you can set parallel thread which will update the file based on events in game ,

2 Likes

This is what I do, except I use SQLite. So I execute a query to update my game data.

Just to make it clear - By parallel thread, does that just mean a multithreaded application or?
For example with std::thread

So if you save data for every event, then if the user clicks on the cookie or whatever every 0.5 sec would that not cause lag?

Thanks! Appreciate your patience haha

std::thread, yes.

I don’t do it every .5 second really. it just happens when it needs to. This is part of the logic you code when you have an object that gets updated. The “how often” to do it is the developers choice. Again, I am using SQLite mostly so this is simply executing a query. SQLite can handle more transactions in a second that I think any game could throw at it.

If you are using a file based methodology it might be wise to have a flag that says the file is open and updating before running code to open again and always make sure to close().

1 Like

But one more thingn - I am not really sure about why you just don’t call a function that saves the data whenever the user finishes an event like clicking instead og running a parallel thread whenever those events finishes or start?

Thanks!

You can do this also , it all depends on your game really …

No memory advantages? I mean running multi threading is just the same as parallel coding to functions to run sanctimoniously right?

I don’t think you would be saving that much data, frequently, to where you would need to be concerned about it to much.

Well thanks. But do you have a rule about when to do what or? Or something that makes you more clarified about when to multi thread or just call multiple functions.

I use threads when I need to execute something and I don’t need a result back to the current thread. This means that I can execute in parallel. If an error happens I can handle it without the user knowing or blocking their play (if appropriate).

Calling multiple function means that you could be blocking something else from happening. Perhaps this is not ideal.

1 Like