Data Storage Question/Suggestion

Forum Listing » Game Achievements Forum » View Topic

  • I have a game with a level editor, and have been working on an oline level sharing option in the game, using the data storage.  Here is how I initially did it:

    -Have a variable ID_NUM stored on the server.

    -When a user tries to upload a level, fetch ID_NUM.

    -Increase the value of ID_NUM by 1, and set it on the server.

    -Upload the various information required to [ID_NUM]_[SOME_PREFIX].  For example, the string required to generate the level is at [ID_NUM]_CODE, and the creators name is at [ID_NUM]_CREATOR.

    -Then the levels can be "linked together" (using more data fields) to, for example, make it possible to retrieve all the most recently uploaded levels.

    However their is a problem with this approach.  What if two users try to upload a level at the same time and get the same ID_NUM?  This would result in the first persons lvel being overwritten!  While it might seem unlike, it is possible, and it's an issue I'd rather avoid.

    So my question is quite simple.  Any ideas?  Has anyone confronted this problem?

    As for my suggestion's, which I do reaize would be quite a bit of work (especially the first one, I'm guessing):

    1) Make it possible to "queue up" several commands and send them all at once, guarenteeing they will all be executed consecutively.

    2)Make it possible to perform simple arithmetic commands on data storage items without having to download and reupload them.  (I do realize they all all stored as strings... don't know how difficut it would be to convert them back and forth.)

    Anyway, besides this small problem, I've really enjoyed working with the system :)

    Last edited on July 9, 2012 - 10:46 PM by Bill

  • Here are a few ideas...

    You could use the Game Jolt user's ID.
    You could have an "is_locked" data store item to check/set when uploading. 

    Neither of those are perfect solutions. In a future version of the API we are looking to have queryable database-like storage (e.g. SQL).

  • Using the user ID is a great  idea, thanks.  I don't think the "is_locked" idea would work.  I actually considered it, but it would generate the same problem as I currently have- checking between when it is checked by someone else and set by someone else.  Unless I misunderstand you, which is possible :)  Doesn't matter anyway, thanks!

  • Also, rather than doing stuff like [ID_NUM]_CREATOR, you should try to get all the fields in one key, so that you have less lookups and things are faster. I would look at using something like JSON for storage. Most tools/languages have parsers for JSON.

     

  • Using the Game Jolt User IDs will work for now, however... This has highlighted an area of the system that we can improve on before release. Huzzah! :D

    A new API endpoint /data-store/update/ will be introduced which will allow you to perform arithmetic and string operations on items in the data store. You will probably need to modify the library or plugin that you are using, but hopefully that won't be too difficult. 

    I'll post here with links to the documentation when the changes go live. 

  • Thanks CROS, looking into JSON now...

    And Ashley that sounds fantastic!

  • Here you go, Bill!

    http://gamejolt.com/api/doc/game/data-store/update/

  • Thanks Ashley!  I just noticed what I think is a mistake on the Game API Doc page- both Keypair and XML are indicated as the default format in there descriptions.

  • Whoops. Thanks for mentioning that, Bill! 

    Keypair is default. Mah

People Online