Cloud Code -> generateCustomValue -> getRequest(userName, testValue ) -> create Value for this User -> return Value
Can somebody plz help me and show how i can do this? Maybe with a small example ?
Thanks !
Best Answer
C
Customer Support
said
about 8 years ago
Hi Eugen,
Here's an event that takes a string (could also be a number or JSON):
The important thing here is that the Default Calc is set to "Used In Script".
Then in the Cloud Code for "generateCustomValue" I have this code:
var customValueToStore = Spark.getData().customValue; //this will get the attribute of the event
var thisPlayer = Spark.getPlayer(); //This will load this user's player object
var thisPlayersName = thisPlayer.getDisplayName(); //This will load the user's displayname
thisPlayer.setScriptData("customValue", customValueToStore); //This will save customValueToStore to the player object's scriptData
//Spark.setScriptData("customValue", customValueToStore); //This will save the custom value to the Response which will be visible on the Inspector in the Test Harness
addToName(thisPlayersName, customValueToStore); //Run the function below
function addToName(playerName, customValueToAdd){
var newCustomValue = playerName + " " + customValueToAdd; //add the two variables from above together
Spark.setScriptData("AddedValues", newCustomValue); //This will save the added values to the Response which will be visible on the Inspector in the Test Harness
}
The key thing to notice here is setScriptData. Spark.setScriptData will ONLY set the ScriptData of the response, which is useful for returning data from a custom event that is immediately usable by whatever game engine you are using.
Spark.getPlayer().setScriptData sets the ScriptData to that player's playerObject, it wont be surfaced in the response unless you use Spark.scriptData also.
Then in the Test Harness I sent the LogEventRequest:
Here's an event that takes a string (could also be a number or JSON):
The important thing here is that the Default Calc is set to "Used In Script".
Then in the Cloud Code for "generateCustomValue" I have this code:
var customValueToStore = Spark.getData().customValue; //this will get the attribute of the event
var thisPlayer = Spark.getPlayer(); //This will load this user's player object
var thisPlayersName = thisPlayer.getDisplayName(); //This will load the user's displayname
thisPlayer.setScriptData("customValue", customValueToStore); //This will save customValueToStore to the player object's scriptData
//Spark.setScriptData("customValue", customValueToStore); //This will save the custom value to the Response which will be visible on the Inspector in the Test Harness
addToName(thisPlayersName, customValueToStore); //Run the function below
function addToName(playerName, customValueToAdd){
var newCustomValue = playerName + " " + customValueToAdd; //add the two variables from above together
Spark.setScriptData("AddedValues", newCustomValue); //This will save the added values to the Response which will be visible on the Inspector in the Test Harness
}
The key thing to notice here is setScriptData. Spark.setScriptData will ONLY set the ScriptData of the response, which is useful for returning data from a custom event that is immediately usable by whatever game engine you are using.
Spark.getPlayer().setScriptData sets the ScriptData to that player's playerObject, it wont be surfaced in the response unless you use Spark.scriptData also.
Then in the Test Harness I sent the LogEventRequest:
Eugen Kasjanov
Hello community,
i want to create a server side script to generate a custom value and return it to the current user.
This is the workflow:
LogEventRequest -> generateCustomValue ( userName, testValue )
Cloud Code -> generateCustomValue -> getRequest(userName, testValue ) -> create Value for this User -> return Value
Can somebody plz help me and show how i can do this? Maybe with a small example ?
Thanks !
Hi Eugen,
Here's an event that takes a string (could also be a number or JSON):
The important thing here is that the Default Calc is set to "Used In Script".
Then in the Cloud Code for "generateCustomValue" I have this code:
The key thing to notice here is setScriptData. Spark.setScriptData will ONLY set the ScriptData of the response, which is useful for returning data from a custom event that is immediately usable by whatever game engine you are using.
Spark.getPlayer().setScriptData sets the ScriptData to that player's playerObject, it wont be surfaced in the response unless you use Spark.scriptData also.
Then in the Test Harness I sent the LogEventRequest:
And received the response:
You can now also send a "getAccountDetails" request and see that we've also stored the Custom Value to the player's scriptData:
Hope this answers your question,
Shane
Customer Support
Hi Eugen,
Here's an event that takes a string (could also be a number or JSON):
The important thing here is that the Default Calc is set to "Used In Script".
Then in the Cloud Code for "generateCustomValue" I have this code:
The key thing to notice here is setScriptData. Spark.setScriptData will ONLY set the ScriptData of the response, which is useful for returning data from a custom event that is immediately usable by whatever game engine you are using.
Spark.getPlayer().setScriptData sets the ScriptData to that player's playerObject, it wont be surfaced in the response unless you use Spark.scriptData also.
Then in the Test Harness I sent the LogEventRequest:
And received the response:
You can now also send a "getAccountDetails" request and see that we've also stored the Custom Value to the player's scriptData:
Hope this answers your question,
Shane
1 person likes this
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics