Sign In Register

How can we help you today?

Start a new topic

Best practice to save some data.

I need to attach some dynamic data to the player like games played, games win counters  as well as some more properties. Which can be updated from the Cloud Code. For example, player can hit the "like" button after the match, and cloud code should update the "Like" counter for opponent. I'm not sure what is the best way to do this. 

Please, help.

Thanks in advance.


The best way to go about this would probably be to create a runtimeCollection for storing your custom data against a given player's id. You could create an entry in this collection each time a player registers:


Spark.runtimeCollection("playerData").insert({

"_id":Spark.getPlayer().getPlayerId(),

....etc

})


Then use a simple mongo update query to change the value against the player when needed, for example, to increment the 'like' count through cloud code, you would use something like this:


Spark.runtimeCollection("playerData").udpate({"_id":Spark.getPlayer().getPlayerId()},{"$inc":{"like":1}});


Try this out and let us know how it works for you.


Regards,

Vinnie


Thanks, this works like a charm.

However, can you help me with the following.

I need to collect two events from two players. Weird, yeah? I'll try to explain:

I have two-players only game.

so, i need to receive "ready" state from both players on Cloud Code side.

And once i'll receive "ready" state from both players, then some additional code will be executed.

I know how to send event from the client (iOS), but i don't know how to keep "ready" state, received from both players.

A little help will be handy here.

If possible I'd like to get a bit more information on this, it should help us provide you with the best approach:


- What specifically are you trying to accomplish with this? Is it some form of custom matchmaking?

- Are the players involved already known at this point or can it be any two players?

- Can the players 'see' each other (i.e. do they have acess to each other's ids)?


Vinnie

Ok, let me explain. Game for iOS devices only. No Unity, cocoa. Pure iOS and Swift.

Just imagine tic-tac-toe game. Each player has a limited time for a move. So, real-time match is used.

How I want to achieve this:

The game field stored on cloud code side. It's an array[9] with 9 cells. Once player made a move, it send GSLogEventRequest with cell number and cross or nought, cloud code keeps this value at certain cell. Then cloud sends the message to the second player containing opponent's move. Also, if cloud code detects that someone wins, or tie -  it sends messages to the both players containing round over and win/loose/tie results.  At this time, players will decide to play another round or quit the match. If they want to play again, cloud code will receive "ready state". Once both players sends "ready", then cloud code will reset the the field (clear array) and send the message to the both players, that game is ready and who has the first move (randomly).
Sending events and messages is not a problem. I don't know how to store values on cloud code side, like game field, booleans for player ready state.


Alex.

How can I access Data Types created on Gamesparks through iOS SDK? I tried to create collection but they are not supported and asked to create data types. I want to keep some quiz questions and related images.


Regards,

Nick

Login to post a comment