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
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 } }) };
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?
Anyway, thank you so much, it all works perfectly now! You are the best ❤️
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