Sign In Register

How can we help you today?

Start a new topic
Answered

Card game with GameSparks

Hi,


I am planning to change PlayFab in my game to GameSparks because PF Unity SDK does not support Windows Store builds. It's a card game where 2 players battle each other.

I used PlayFab to store the attributes of the cards.(e.g.: attack, defense values, card ID....) and when the game starts I sync the attributes of the currently available cards with the latest version using the values stored on the PF server.


How can i do the same with GameSparks? 

As far as I see each card would be a Virtual Good which can be obtained by the player. But how can I set the attributes here? If I have 100 cards do i have to create 100 property set with 100 property? If i introduce a new attribute to the card do I have to update each 100 property individually?


Best Answer
Hey Gabor,

You certainly can do it that way. Actually, since you will be trading cards using currency, having your cards be virtual goods is an excellent idea. I've advised a couple of folks about card games with GameSparks, and i had a facepalm moment when i saw you ask about using them as virtual goods. Thats a very good way of tracking them.
However, you get into the problem you've just asked about, and that is properties that each card needs.

But, yes, if you use property sets for giving your cards attributes you will have a very boring and frustrating time updating and managing your cards.

I would suggest, in the interest of speedy-development, that all possible cards are kept in a collection. The benefit of this is that you can create, edit, delete them through a manage-screen you can customize yourself. Another benefit is that each card has a unique object id, and will never match another card in the collection. Using these, you can get the player's private data to store a list of the unique id's of the players current inventory of cards. You can, of course store a whole list of card-documents in the player's private data, but in the event that that list gets too large for mongo-db, the unique id will be smaller. It is also safer, as player's who try to inject-code or hi-jack server responses, wont have a direct reference for any card, just a random id.

You can then have more log events that take the id and get the document information for each card.

I do like the idea of have cards be virtual goods, but from experience using GameSparks, my advice is to have your card collections as broadly editable and manageable as possible. So a custom collection is the way to go.

Let me know if that helps,
Sean

 


Answer
Hey Gabor,

You certainly can do it that way. Actually, since you will be trading cards using currency, having your cards be virtual goods is an excellent idea. I've advised a couple of folks about card games with GameSparks, and i had a facepalm moment when i saw you ask about using them as virtual goods. Thats a very good way of tracking them.
However, you get into the problem you've just asked about, and that is properties that each card needs.

But, yes, if you use property sets for giving your cards attributes you will have a very boring and frustrating time updating and managing your cards.

I would suggest, in the interest of speedy-development, that all possible cards are kept in a collection. The benefit of this is that you can create, edit, delete them through a manage-screen you can customize yourself. Another benefit is that each card has a unique object id, and will never match another card in the collection. Using these, you can get the player's private data to store a list of the unique id's of the players current inventory of cards. You can, of course store a whole list of card-documents in the player's private data, but in the event that that list gets too large for mongo-db, the unique id will be smaller. It is also safer, as player's who try to inject-code or hi-jack server responses, wont have a direct reference for any card, just a random id.

You can then have more log events that take the id and get the document information for each card.

I do like the idea of have cards be virtual goods, but from experience using GameSparks, my advice is to have your card collections as broadly editable and manageable as possible. So a custom collection is the way to go.

Let me know if that helps,
Sean

 

Hi,


Thanks for the fast and detailed answer. I like that idea very much.

But I have another question:)

When I create the collection what is your suggestion? Runtime and metadata collection? The only difference between the two is that runtime is read/write and metadata is read only? Then I should go with metadata.


Thanks,

Gábor

I usually go with runtime because you want to be able to edit things while your game is live too. Especially annoying things you will encounter like typos or game-breaker balancing issues you might have with cards. I predict you'll want to fix and edit those quickly, so a runtime collection gives you that freedom. You just make sure that the client is only ever retrieving data about one entry and not sending data into that collection, so you control the collection from your portals manage screen only.

Sean

 

Thanks! Great support!

I have create the runtime collection but again i have another question

I want to give the player some starting cards for free when they register


I wrote a Cloud Code for the Registration Respone but it isn't working:


var currentPlayer = Spark.getPlayer();


if(currentPlayer){

    var query = { "Type" : "Free"};


    var cards = Spark.runtimeCollection("card");


    var freeCardIds = cards.find(query, {"_id" : 1});

    var freeCardCount = freeCardIds.count();

    

    if(freeCardCount > 0){

        currentPlayer.setPrivateData("playerCards", freeCardIds);

    }

}


When debugging I see that the freeCardCount is 1 so the the setPrivateData get executed, but when i query the player with NoSQL the private data is empty... also tried to use JSON.stringify on it before storing it. It was a little bit better because the private data was populated with  "playerCards": "{}, but the IDs were missing.

Can you help me out? I think I'm missing some very obvious thing here...


Br,

Gábor



Okay,

If you try to parse your query to an array using...

 var freeCardIds = cards.find(query, {"_id" : 1}).toArray()

 

When you step through the code in the test-harness you should be able to see exactly what you have there, i.e. the card Ids
My thinking is that the cursor either didnt find anything or count() isnt working properly.
Either way, casting the query to an array will  show you this and insert the cards into the player data the same way.

You could also try freeCardIds.hasNext() as an alternative check to count() or size(), as ive recently encountered problems with these methods when using a mongo cursor.

Sean

It's working this way. I converted the mongo cursor to an array just as you suggested and now I am able to store it in the private data.


Thanks again for the great support!


Br,

Gábor

Sorry to reply in an old post, but it's THE BEST SUPPORT I've ever seen!

Login to post a comment