question

bomdur88 avatar image
bomdur88 asked

Round to int (Cloud Script)

Hi, i'm using cloud script to calcule the player score. The thing is: i want to round the value to an int but i don't know how to do it (Using (int)value or math.round isn't working)

Example of what i'm trying to do:

function TimeScore(MatchTime)
{    
    var lerpTime = ( MatchTime - 45.0) / (360.0 - 45.0);
    
    var timeScore = 8000 + lerpTime * (2000 - 8000);

     return Math.round(timeScore);
}

I want to convert timescore into an INT

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

The CloudScript (Legacy) runtime environment supports most of the modern ECMAScript 6 features. Thus, you can use Math.round() function to get what you want. I have done a test with code below, it does round the “timeScore” to an int. Please give a try. For more info about writing Cloud Script (legacy), please refer to Writing custom CloudScript (Legacy) - PlayFab | Microsoft Docs.

handlers.Sample = function (args)
{
  var MatchTime = args.MatchTime;
  var lerpTime = ( MatchTime - 45.0) / (360.0 - 45.0);
  var timeScore = 8000 + lerpTime * (2000 - 8000);
  return Math.round(timeScore);
};
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bomdur88 avatar image bomdur88 commented ·

it worked, thank you

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.