SFSDataType.UTF_STRING_ARRAY requires an array of string values

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

nik0990
Posts: 76
Joined: 23 Dec 2016, 10:48
Location: India

SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby nik0990 » 25 Feb 2019, 11:28

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)
"
nik0990
Posts: 76
Joined: 23 Dec 2016, 10:48
Location: India

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby nik0990 » 25 Feb 2019, 11:43

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.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby Bax » 25 Feb 2019, 12:19

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.
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby Bax » 25 Feb 2019, 13:07

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.
Paolo Bax
The SmartFoxServer Team
nik0990
Posts: 76
Joined: 23 Dec 2016, 10:48
Location: India

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby nik0990 » 25 Feb 2019, 13:49

Hi,

Thanks for help.

But still My "typeof array " is coming object. and facing same issue
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby Lapo » 25 Feb 2019, 15:09

Can you please reply to this?
What version of the JavaScript API are you using?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
nik0990
Posts: 76
Joined: 23 Dec 2016, 10:48
Location: India

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby nik0990 » 26 Feb 2019, 05:09

Hi,

SmartFoxserver Javascript Api 1.7.14
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: SFSDataType.UTF_STRING_ARRAY requires an array of string values

Postby Bax » 26 Feb 2019, 06:41

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);
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 18 guests