Sign In Register

How can we help you today?

Start a new topic

LogEvent error codes

Hi!

I'm using an Event to modify the Player's currency, and i would like to know how should i handle errors like player currency invalid or the result of a debit being < 0.


Do i have to handle all of this in my cloud code? Does the LogEvent fails and sends me some sort of error code?


This is my cloud code:

  

var toAdd = Spark.getData().amount; // we can get the cash we intend to grant to the player
var ID = Spark.getData().currencyID;

if(toAdd < 0)
{
    toAdd *= -1;
    Spark.getPlayer().debit(ID, toAdd);
}
else
{
    Spark.getPlayer().credit(ID, toAdd);
}

 Thanks!


Ok, that clears it up, thanks!!

If any of the attributes you specified in your event setup are missing or of invalid type in the LogEventRequest it will automatically trigger an error. For more specific checks like the debit one you mentioned this would need to be handled in cloud code. For the provided example, the 'debit' function returns a boolean indicating whether or not the debit was successful; if the user has insufficient funds to perform the debit it will return false, so you could do something like:


var result = Spark.getPlayer().debit(ID, Math.abs(toAdd));

if(result) Spark.setScriptData("success", true);

else        Spark.setScriptError("error":"insufficient_funds");


Regards,

Vinnie

Login to post a comment