Page 1 of 1

SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 25 Feb 2019, 11:28
by nik0990
Hi,

I am upgrading my SFS server from 2.9.2 to 2.13.4 and facing few issues.

I am putting a string array to "putUtfStringArray" but getting error each time.

Code: Select all

         var params = new SFS2X.SFSObject();
        //var a = new SFS2X.
        params.putUtfStringArray("opponents",[opponentId.toString(),""]);
        params.putInt("action",7);
Getting this error.
"SFSTypeError
Invalid value passed; type SFSDataType.UTF_STRING_ARRAY requires an array of string values
STACK TRACE: SFSTypeError: Invalid value passed; type SFSDataType.UTF_STRING_ARRAY requires an array of string values
at t (http://localhost:9000/vendor/sfs/SFS2X_API_JS.js:6:1971)
at new t (http://localhost:9000/vendor/sfs/SFS2X_API_JS.js:6:2362)
at Object.validate (http://localhost:9000/vendor/sfs/SFS2X_API_JS.js:6:8264)
at e.value (http://localhost:9000/vendor/sfs/SFS2X_ ... js:6:11633)
at e.value (http://localhost:9000/vendor/sfs/SFS2X_ ... js:6:12821)
at Object.that.eraseUsersNotes (http://localhost:9000/scripts/services/ ... .js:976:16)
"

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 25 Feb 2019, 11:43
by nik0990
I also Tried

Code: Select all

 function toUTF8Array(str) {
    var utf8 = [];
    for (var i=0; i < str.length; i++) {
        var charcode = str.charCodeAt(i);
        if (charcode < 0x80) utf8.push(charcode);
        else if (charcode < 0x800) {
            utf8.push(0xc0 | (charcode >> 6), 
                      0x80 | (charcode & 0x3f));
        }
        else if (charcode < 0xd800 || charcode >= 0xe000) {
            utf8.push(0xe0 | (charcode >> 12), 
                      0x80 | ((charcode>>6) & 0x3f), 
                      0x80 | (charcode & 0x3f));
        }
        // surrogate pair
        else {
            i++;
            // UTF-16 encodes 0x10000-0x10FFFF by
            // subtracting 0x10000 and splitting the
            // 20 bits of 0x0-0xFFFFF into two halves
            charcode = 0x10000 + (((charcode & 0x3ff)<<10)
                      | (str.charCodeAt(i) & 0x3ff))
            utf8.push(0xf0 | (charcode >>18), 
                      0x80 | ((charcode>>12) & 0x3f), 
                      0x80 | ((charcode>>6) & 0x3f), 
                      0x80 | (charcode & 0x3f));
        }
    }
    return utf8;
}
but having same error.

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 25 Feb 2019, 12:19
by Bax
A super fast test in the browser didn't show issues:

Code: Select all

> o = new SFS2X.SFSObject()
Object { _dataHolder: Map(0), _serializer: {} }

>o.putUtfStringArray('k', ['uno','due'])
undefined

>o.getDump()
"
	(utf_string_array) k: uno,due
	
"
What version of the JavaScript API are you using? Make sure you download the latest version from our download page.

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 25 Feb 2019, 13:07
by Bax
That error could be triggered by the first element in the array not being a string.
Make sure that "opponentId.toString()" actually returns a string and not a null value.

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 25 Feb 2019, 13:49
by nik0990
Hi,

Thanks for help.

But still My "typeof array " is coming object. and facing same issue

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 25 Feb 2019, 15:09
by Lapo
Can you please reply to this?
What version of the JavaScript API are you using?
Thanks

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 26 Feb 2019, 05:09
by nik0990
Hi,

SmartFoxserver Javascript Api 1.7.14

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Posted: 26 Feb 2019, 06:41
by Bax
nik0990 wrote:Hi,

Thanks for help.

But still My "typeof array " is coming object. and facing same issue
In JavaScript typeof array always returns object.
What if you create and send a simple array like this?

Code: Select all

var a = ['one','two']:
var o = new SFS2X.SFSObject();
o.putUtfStringArray('k', a);