question

yogev avatar image
yogev asked

Question about playfab and cloud script

Hey I have 2 questions if you can help me with

and thank you

1 - I want to let the player buy the item only after a few checks and I think the best place to put this is inside the azure function what is the namespace/ API that I can use inside azure function to buy the item for the player?

2 - I am storing the display and expiration date inside the custom store data, and I saw that there is a limit of 1000 bytes is there another place to store it with a bigger limit or a way to make it cheaper? because Its not much I only can store 20 +- players and dates and if I store only name and date its around 40 - 50 bytes I just want it for name and date

can I maybe store it inside the metadata? that has 10k limit

this is the current code that I use - https://pastecode.io/s/t0nba56w

CloudScript
10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

In the previous post, you mentioned that

I have a shop where the player can buy cities, and only one player can buy this specific city then it will give him the item with the expression data then after he buys it , and then I want to get the owner's info.

In my tests, each store item can store 1000bytes data. I thought you only need to store one player's info as only one player can buy it. If you need to store more data and it may be modified by multiple players, as @drallcom3 mentioned, an external database would be better. You can refer to Azure Databases.

To implement purchasing in Azure Function, you need to subtract currency and grant items manually. Refer to Subtract User Virtual Currency and Grant Items To User.

10 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.

yogev avatar image yogev commented ·

Ohh I see thank you, yes its only one player per city but thanks I will check the user database

0 Likes 0 ·
yogev avatar image yogev commented ·

Can I just buy for him the item and then get the expiration date and send it to the database? with the purchase API like in unity? because it will be better than getting the item from getting all the items from the catalog and getting the item price etc it's a bit waste of resources

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao yogev commented ·

Purchase directly on the client without checking the item status may cause that multiple players buy the same item. If you store the item owner info in the external database, then you don't need to get the Catalog info frequently, since there won't be many changes on the Catalog.

0 Likes 0 ·
yogev avatar image yogev Gosen Gao commented ·

Thank you so much Yes I am checking first with my external database is it ok to use the Purchase API? because it will be much easer
my flow is like this - checking if there is owner > if not try to buy the item > if good get name and expire date and send to the database

0 Likes 0 ·
yogev avatar image yogev commented ·

Hey, another thing for some reason sometimes when I execute the function it will do it 2 times why? in unity I only invoke it one time but when I check the logs inside azure it showed that it executed 2 times

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao yogev commented ·

You can add some debug in the AF invocation logic to see if it has been called twice. Or you can test it with Postman to see if the issue persists.

0 Likes 0 ·
yogev avatar image yogev Gosen Gao commented ·

Thanks I saw it on the log streaming I saw it invoke 2 times on unity, I invoke it one time it does sometime invoke it one time i will continue to monitor it

thank you

0 Likes 0 ·
yogev avatar image yogev commented ·

Another thing how can I execute the functions like queue or something to allow only one player to buy the item

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao yogev commented ·

You can implement your AF as Queue trigger, refer to Azure Queue storage trigger and bindings for Azure Functions overview.

0 Likes 0 ·
yogev avatar image yogev Gosen Gao commented ·

Thank you I will check it out

0 Likes 0 ·
drallcom3 avatar image
drallcom3 answered
  1. Yes.

  2. You don't store player names in the custom store data. Player specific data belong into player data.

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.

yogev avatar image yogev commented ·

Thank you ,

1 - for the first one do you know the API or name space that I can use for it ? its not in the serverapi ot admin

2 - I store it because I have a system that I need all the players and the expiration date of the item is there any other way to do the custom data?

0 Likes 0 ·
drallcom3 avatar image drallcom3 yogev commented ·

I you need a central source for global data and all players could at any time all write to it, then Playfab doesn't have any reliable system for that.

0 Likes 0 ·
yogev avatar image yogev drallcom3 commented ·

but playfab does have this with their custom store data and Its working fine for me its just the limits even playfab support told me that I can use the custom store data

I don't need the players to right it any time only when they buy a item and I use azure function to do this

0 Likes 0 ·
Gosen Gao avatar image
Gosen Gao answered

Since the PurchaseItem API is a client-side API, you can only perform the process on the client side, which is not safe. I have an idea is:

  1. Check database to see if there is owner, if not try to buy the item(Execute the AF). - client

  2. Check database to see if there is owner -> if not subtract the currency, grant the item -> update the database -> call Player Item Management - Increment Limited Edition Item Availability to add one to the item. - AF

With the Limit Edition item, even multiple players buy the same item at the same time, only one can get the item. After updating the owner, only one item is always available for purchase by adding another item to the restricted editor items.

9 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.

yogev avatar image yogev commented ·

Thank you so much !! I will do it as you said its a good idea but about the Limit Edition, the thing is the item will expire after one day will it auto reset the Limit Edition counter?

about the subtraction thing, how can I get the item price? I know about the getstoreitems function because there are over 200 items and I don't want to get all the items it will waste resources can I get only one item with the id? or some how get only the price of it ? because I cant trust the client to send me the price

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao yogev commented ·

The thing is the item will expire after one day will it auto reset the Limit Edition counter?

It is not, so I mentioned that call API IncrementLimitedEditionItemAvailability to add one to the item manually.

about the subtraction thing, how can I get the item price?

SInce you have a database, you can store any necessary info there.

0 Likes 0 ·
yogev avatar image yogev Gosen Gao commented ·

Thank you, so I have 2 ways one getting items from playfab but it will be a bit of waste

and the second one is getting it from my database but then it will make my work a bit harder Because I will need to update the prices and stuff on 3 different places

if I will pull the items from playfab like 500 items will I pass any limit? and how much time could it take?

0 Likes 0 ·
Show more comments
yogev avatar image yogev commented ·

oh and another thing , is there any limit on how many times I can run cloud function?

thank you

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao yogev commented ·

There is no specific limit on executing Azure Functions.

0 Likes 0 ·
yogev avatar image yogev Gosen Gao commented ·

Thank you

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.