How do I combine DataBase and Local DataBase

Get help using Construct 2

Post » Wed Nov 23, 2016 11:50 am

In my mobile game i use local database (NeDB by @rexrainbow) and on-line database (Firebase by @rexrainbow). So I'm confused how to use them together. Earlier i used this logic: Saving data (while playing) in NeDB and Firebase, then after next enter in game take data from NeDB, but if NeDB is empty, then try to take data from Firebase. And if it is empty too, then player entered in this game the first time. I thought this logic is the best, but it wasn't. This logic is very unstable and unreliable. So could you give me any advice?
B
36
S
13
G
2
Posts: 200
Reputation: 3,868

Post » Wed Nov 23, 2016 4:33 pm

@norman74

Why reading NeDB first?
You might try to
1. read firebase first each time
2. if read result is invalid, initial(write) the table in firebase from a default JSON data, also takes this data as read result.
3. put result into taffydb to have more powerful querying ability.
B
110
S
28
G
280
Posts: 4,488
Reputation: 156,568

Post » Wed Nov 23, 2016 5:53 pm

@rexrainbow

I tried to use taffy, but i like nedb because it's easier :)

How i understand:
If on-line -> Load from firebase
If offline -> Load from nedb
right?
So, will this work if my game even can be opened in offline mode?
B
36
S
13
G
2
Posts: 200
Reputation: 3,868

Post » Thu Nov 24, 2016 7:15 am

What is your purpose of saving data on cloud?
I suppose that you want to provide a seamless app which could be started from previous status at any platform.

Your app stores data in local storage in offline mode, and player might have more than one offline saving status (at different device). These offline saving data might be inconsistent when they upload to cloud.
And, player won't get the latest data from cloud, because that app checks local storage first and he had saved data at local storage already.
B
110
S
28
G
280
Posts: 4,488
Reputation: 156,568

Post » Thu Nov 24, 2016 8:44 am

@rexrainbow

Yes, that people could use one account on different devices and also to restore data if user deleted all local data
B
36
S
13
G
2
Posts: 200
Reputation: 3,868

Post » Thu Nov 24, 2016 8:54 am

@norman74

How about treat saved data as files (slots) stored in cloud or local storage.

For example,
Open: player opens his local files menu and pick one file to play it
Download: player opens his cloud files menus and pick one file to download it into a local file.
Upload: player uploads a file from local to cloud
New: player initials a file in local

Player only could see his local files menu if off-line, and he could download or upload files if on-line.
Local file won't be overwrote until player download a file from cloud.
B
110
S
28
G
280
Posts: 4,488
Reputation: 156,568

Post » Thu Nov 24, 2016 10:26 am

@rexrainbow

I'm not sure about that. This game is "clicker", so probably auto-save variant would be much better than semi-auto.
B
36
S
13
G
2
Posts: 200
Reputation: 3,868

Post » Thu Nov 24, 2016 3:36 pm

The strategy is not only the order of reading cloud data or local storage.
The main problem is how to manage inconsistent saved data between devices and cloud, imo -- discard or merge the saved data.
For example, if the saved data in local storage is older or newer than cloud, you might discard the older one.

Or store the command sequence (actions at time) instead of game status (value of variable), therefore you could merge the command sequence to rebuild the latest game status. It depends on your game design.
B
110
S
28
G
280
Posts: 4,488
Reputation: 156,568

Post » Thu Nov 24, 2016 4:17 pm

@rexrainbow

Hmm, It's quite good decision, but if imagine this situation: we have 2 devices: "A" and "B". I use "A" and play in my game for one week in offline. There I reached, for example: 25 coins and 100 diamonds. In B a play a little bit more in online, but reached 10 coins and 15 diamonds. Then this data from device "B" (10 coins and 15 diamonds) will be the newest. And if i connect to cloud device "A" which were in offline, then it will take all data from cloud and he will lose a lot coins&diamonds.

So, will it be reasonable in this case to use this system?
B
36
S
13
G
2
Posts: 200
Reputation: 3,868

Post » Thu Nov 24, 2016 11:49 pm

@norman74

It depends on your design.
I would like enforce player only could run app when device is on-line, to avoid data inconsistent issue.
B
110
S
28
G
280
Posts: 4,488
Reputation: 156,568


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests