question

steelfox001 avatar image
steelfox001 asked

Unity how realizate bet?

Hi. In my game Player make bet on number 1-6 and roll 3-6 dice if dice with number come he win depending on how many dice have this number. I want use virtual currency for bet, but i find only way to buy items from client side. How the best way resolve the problem with bet? Second question is how save game history?

Player Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

One way to do this would be to write a Cloud Script that takes the bet input from the client and does the random calculation for the roll. It would then add or subtract VC based upon the win/loss, and return that info to the client so that you could present that to the user (animations, etc.). The Server API calls SubtractUserVirtualCurrency and AddUserVirtualCurrency would be the ones to look at.

For saving info on game history, you could save recent games in user data, or use the Content service if you want to save the user's call history for all time and let them download it (though you would want to use a custom game server at that point, so that it can manage the upload of that content).

Alternately, if you only want to have all the historical data for your own analytics, you could write a custom event to PlayStream for each bet, and then save that to your own S3 bucket via the PlayStream event archive.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

steelfox001 avatar image steelfox001 commented ·

Thank you Brendan.

Do I have option to cast result from PlayFab Cloud Script?

In Unity using

Debug.Log(result.FunctionResult);

I see Array

{"kosti":{"0":2.0422988431528211,"1":1.3973219902254641,"2":5.6558654932305217,

"3":5.5935304556041956,"4":4.6412557000294328,"5":1.737095810007304,"6":1.7536969417706132,

"7":5.73065363895148,"8":4.3100328114815056,"9":5.5574326189234853}}

but this cast return error

tempArrv= (float[]) result.FunctionResult;

InvalidCastException: Cannot cast from source type to destination type. HelloWorld.OnCloudHelloWorld (PlayFab.ClientModels.ExecuteCloudScriptResult result) (at Assets/HelloWorld.cs:34) PlayFab.Internal.PlayFabHttp+

----------------------------

handlers.helloWorld = function (args, context) {

var kosti ={};

for (var i=0;i<10;i++){

kosti[i] =((Math.random() * 6) + 1);

}

return { kosti };

-----

0 Likes 0 ·
brendan avatar image brendan steelfox001 commented ·

What you're getting back isn't an array of floats - it's a JSON array. For example, have a look at this post: http://stackoverflow.com/questions/9419303/json-array-javascript.

The array you get back - "kosti" - is a key/value pair array. So, kosti[0] is 2.0422988431528211, kosti[1] is 1.3973219902254641, etc. But notice that "0" and "1" are strings in the response - that's because they're the keys in the key/value pairs.

One of the easiest ways to work with the results is to simply write the whole FunctionResult out to a string, so that you can look at the format of everything you've returned and work out how best to use it.

1 Like 1 ·
steelfox001 avatar image steelfox001 brendan commented ·

Thanks. Resolve!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.