Sign In Register

How can we help you today?

Start a new topic

Cloud Scripting

I've been loking through the tutorials.

In this Cloud Scripting one :

We are setting the Gold from Unity Client to 100, but what i want, is to make a script in the Cloud to setGold = 100, and then cal that Script from the Client.

I don't trust the Client to set the value of Attributes.

Is it possible to do what I pretend?

Thank you for your response. What I really wanted to do is this cloud script.

var playerDataList = Spark.runtimeCollection("playerData"); // this will get the collection of player data

var playerID = Spark.getPlayer().getPlayerId(); // first we get the id of the current player //

var playerUsername = Spark.getPlayer().getDisplayName();

var currencie = Spark.getPlayer().getBalance("GOLD");

Spark.getPlayer().credit("GOLD", 25, "Test Currencies");

var currentPlayer = {

"playerUsername": playerUsername,

"playerID": playerID,

"currencies": currencie };

playerDataList.update({ "playerID": playerID },

{ "$set": currentPlayer }, true,     false );

And then call this Event on Unity :

new GameSparks.Api.Requests.LogEventRequest() .SetEventKey("SAVE_PLAYER") .Send((response) => { ....

Your documentation is the best! :D

Is this safe to do, or can a cheater just call the function over and over to Grant them gold?

Hi Flávio,

One option here might be to validate the attribute first with Cloud code, so for example if you know that the max value can't exceed 100 then you could perform a simple if statement to readjust it back down to the max value or to cancel the entire operation as you know someone has attempted to cheat. If however its a default value that everyone gets when the event is called you could specify the value in a meta / runtime collection or inline rather than have the value passed in as an attribute from the client. I hope this helps.

Kind regards,

 - Steve

1 person likes this
Login to post a comment