question

Kim Strasser avatar image
Kim Strasser asked

CloudScriptExecutionTimeLimitExceeded error message

I get an error message if I want to find out in Cloud Script if the first or the last character in a string is a white space:

handlers.VerifyTextSpaceBeginningEndPassword = function (args, context)
{
   var text = args.text;
   var notSupportArray = new Array();
   for (var i = text.length - 1; i >= 0; i--)
   {
        var charCode = text.charCodeAt(i);
        if ((i = text.length - 1) || (i == 0))
        {
            if (charCode == 32)
            {
                notSupportArray.push(charCode);
            }
        }
   }
    
    if (notSupportArray.length == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

What is wrong? Why am I getting "CloudScriptExecutionTimeLimitExceeded" error message?

 "Error": {
            "Error": "CloudScriptExecutionTimeLimitExceeded",
            "Message": "The script execution was terminated after the maximum execution time limit",
            "StackTrace": null
        }
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

·
Rick Chen avatar image
Rick Chen answered

I notice that in your code snippet 1, line 8, variable i is assigned again with the value “text.length – 1” inside the for loop. This could create an infinite for loop as the variable i never goes down to 0.

There is a time limit for CloudScript to execute a function, you can check it inside [Game Manager] -> [Your Title] -> [Title Setting] -> [Limits]. The infinite for loop triggers the time limit, and you will receive error "CloudScriptExecutionTimeLimitExceeded".

I think line 8 should be:

if ((i == text.length - 1) || (i == 0))

where the first condition should be a double equal mark.

10 |1200

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

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.