Sign In Register

How can we help you today?

Start a new topic

Events which use the same fields but are updated with different values

Hi team,

Firstly - Big, BIG fan of your services. I've read a significant amount of your documentation and a huge thank you to Liam and Patrick, you have resolved many issues i've had just by answering others questions thoroughly.

I'm quite certain this should be a relatively simple request and there's just some documentation that i'm missing, so i'll explain how my game works at take it from there.

The game is a tap combat game, you have a party of up to 4 hero's on the screen at once (like final fantasy styled games), you gain exp for killing enemies and that exp is spent on stats. stats increase damage but also allow you to purchase equipment.

I am looking for a way to essentially store each characters multipliers, stat levels and equipment levels in the database.

The most simple way i could think of doing this is by creating an event called SAVE_CHAR_0, then increment by 1 for each class. Each event has about 9 attributes at the moment. The idea would be that i would parse in which character class i am as an int (already set up in unity) to my SetEventKey which would then determine which class i am updating.

example code in my head would be something like:

new GameSparks.Api.Requests.LogEventRequest()

                .SetEventKey("SAVE_CHAR_" + mainCharClass.ToString())

                .SetEventAttribute("WEAPON_LV", mainForgeWeapon) 

                .SetEventAttribute("ARMOR_LV", topforge)

                .SetEventAttribute("HELMET_LV", 100)

                .SetEventAttribute("SHIELD_LV", 10)

// there would be maybe another 8 or so attributes in here

                .Send((response) => {

                if (!response.HasErrors)


                    Debug.Log("Character Class Saved To GameSparks...");




                    Debug.Log("Error Saving Player Data...");



now - i haven't tested this yet, but i imagine this would likely work. my issue however, is that i would like to have about 30ish classes. In my scenario i'm looking at repeating the same structure of event 30 times to essentially get the same thing. Being relatively new to programming entirely I could see that there probably would be a way to do this. I know in unity i would use a scriptable object then just fill in those objects, load in an array of scriptable objects and bam my characters are ready to be spawned in as needed.

How would i replicate this in gamesparks? Is my solution already viable or am i creating a significant amount of work for myself?

I've tried going through your collections tutorial, but at the moment i'm just not really grasping it, so i'm not sure if it would be applicable to this scenario.

Finally (and sorry for the multitude of questions), i've been building this in through i believe is referred to as the runtime collection, but i'm also very conscious of how frequently i would be updating this - people would sometimes beat a boss then level up strength 5 times then upgrade a piece of equipment, that would be the equivalent of 6 calls in quick succession, am i looking at bandwidth issues or just being paranoid?

Again - i truly appreciate the work you guys put into answering not just mine but all users queries, i look forward to hearing from you :)


You probably want to create a collection in GameDataService, called PlayerStats, using the player's Id as the key. From here you can put any number of fields /stats on the document. Read the docs again for GameDataService and try following the Hearthstone example in the docs. As far as your event goes, you dont want the player to tell the server which stats have increased - it would make cheating way too easy. Instead, you should only have the player control the character and have the server decide for himself if a characters stats increased. This is what Server Authoritative means - I'd suggest googling that time to read more about it unless you dont care about cheating for some reason

Thanks Drew,

I appreciate the answer. I'll have a look at both Server Authoritative as well as the GameDataService documentation.

I'll post my findings here as well so people won't have to ask this again in future.


Hi drew, Yes, I've read all 4 parts to it. I've also gone through the hearthstone tutorial aswell now. I understand how server authoritative works now too, in short it's that clients send requests, servers then validate and update values in the client. This makes sense, however the actual implementation of this im not sure I understand. The client side makes sense to me, however the only things Ive done in cloud code at the moment is basically to say what data will be updated. For me to do validation server side it would mean my values would need to be driven from there. Say for example, my exp. Say my exp is equal to all 4 of my currently active characters (stats * respective multipliers) + (weaponlv * weapon multiplier). That exp ticks every 2 seconds. Client side, not a problem. Server side.... Closest thing I've read is a scheduler which seems to be limited to minute intervals. Alternatively I could potentially see a way to have it only calculate based on tine past each time the client sends a request that would look to spend it, then have client side remain the same. How I would actually do this in cloud code though, I'm not really sure. Sorry, learning fast but I've never written anything in JSON until last week sunday


From a high level, the concept you are trying to come up with is called a "Game Server" or what I'd call a "Game Simulation Server" to be more specific.. Since there can be many types of servers in Games (matchmaking, authorization, persistence, etc...).

Basically, you need something running the simulation on the server side. This is what makes multiplayer games so hard - you need to be able to have the game running on the server, and the player clients are basically just giving inputs to their characters (such as t "I'd like to move north"). 

This means your game client would take in an input of the up arrow being pushed and translate it into a request to the server "id like to move north". Often times the game client would automatically start moving the user north and simulating physics locally, but on the server side, it is doing the same thing and checking that the players requests are valid (e.g. there's no wall there, they aren't paralyzed, etc...).

This is why real-time physics games are so hard.

To solve this problem, I think you have 2 options. 1) look at the Real Time functionality of GameSparks, or 2) build your own simulation server and have GameSparks do a hand-off to them.

One option for hosting simulation servers in option 2 would be in AWS, where you could take advantage of something like GameLift which would help you scale up automatically. Of course this depends on what kind of game you are making - an MMO will have a lot different architecture than an FPS.

Login to post a comment