Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Martin · Jun 01 at 12:48 AM · CloudScriptPlayer Dataunreal

Is it possible for the Key to be a variable and change according to the passed argument?

Hi everyone!

I recently got my hands on PlayFab in order to use it in my Unreal Engine project. Unfortunately, I ran into a problem when working with Cloud Script - Revisions(Legacy) and I can't figure it out.

In particular, it is about updating/creating player data.
If I decide to use PlayFab's plugin for Unreal Engine and its UpdateUserData function, I am able to insert a JSON object in Key:Value format (for example "Games" : "5") and everything works fine.
The player will create this pair within his Player Data (Title) where the number of games will be stored.

However, the problem appears when I want to define this function directly in Cloud Script (Revisions). I have created a function that has 2 parameters - KeyName and ValueName (to create a Key:Value pair). These 2 parameters are then stored in 2 variables - var Key and var Value. In this function, I further use UpdateUserData, where I try to enter these two values (Key and Value variables) - however, if I do this, only Value variable takes the actual value that the user enters as an argument and Key part (within Data) ignores the user's input and uses only the variable name itself (or whatever is entered there) and not what is stored in it.

I would also like to add, that both of these variables actually have the correct value from user/caller when I use the logging to verify it, but the Data part simple doesn't take the Key one.


It is little bit complicated to explain in plain text, so I will attach some screenshots to demonstrate it.
I can attach only 2 screenshots, so the rest can be found here - https://imgur.com/a/nJGf534


customkey.png (21.4 kB)
player-data-title.png (60.4 kB)
Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Gosen Gao · Jun 01 at 02:25 AM

Please replace your Cloud Script handler with the code snippet below.

handlers.CTsDynamicKey = function (args, context) {
    let Key = args.KeyName
    let Value = args.ValueName
    
    server.UpdateUserData({
        PlayFabId:currentPlayerId,
        Data:{
            [Key]:Value
        }
    })
};

Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Martin · Jun 01 at 02:17 PM 0
Share

Oh... I see! So, they Key has to be inside of [] brackets in order for it to accept the data/value from inside the variable?

avatar image Martin · Jun 01 at 02:44 PM 0
Share

Anyway, thank you so much, it all works perfectly now! You are the best ❤️

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    Error : CloudScriptAPIRequestCountExceeded 2 Answers

    How can I access user's ip address from cloudscript? 2 Answers

    No confirmation email is received. 5 Answers

    There is a problem with the certificate when using the container. 1 Answer

    Make a segment of users who logged in 3 times in past month? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges