How do I combine DataBase and Local DataBase

1 favourites
  • 10 posts
From the Asset Store
Ludo Local Multiplayer board game can be played by 2 to 4 players
  • 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?

  • 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.

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • rexrainbow

    Yes, that people could use one account on different devices and also to restore data if user deleted all local data

  • 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.

  • rexrainbow

    I'm not sure about that. This game is "clicker", so probably auto-save variant would be much better than semi-auto.

  • 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.

  • 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?

  • It depends on your design.

    I would like enforce player only could run app when device is on-line, to avoid data inconsistent issue.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)