foreach on SFSObject

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Tatanan
Posts: 112
Joined: 07 Jan 2014, 12:12
Contact:

foreach on SFSObject

Postby Tatanan » 19 Jan 2015, 17:19

Which is the proper way to make a "foreach" loop on a SFSObject?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: foreach on SFSObject

Postby Lapo » 20 Jan 2015, 16:41

SFSObject means SmartFoxServer 2X, so this is the wrong section ;) I'll move the topic.

A for each is kind of a complicated thing to do because you don't know which type of object and key you're expecting.
It can be done but you should probably describe more clearly what you're trying to do.

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Tatanan
Posts: 112
Joined: 07 Jan 2014, 12:12
Contact:

Re: foreach on SFSObject

Postby Tatanan » 20 Jan 2015, 16:55

Ok, thanks.
I put it on the server forum because we wanted it to do on the server (on Java), but it's clear.
I'll try to make without the foreach loop.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: foreach on SFSObject

Postby Lapo » 20 Jan 2015, 17:10

If you're expecting a number of items try using an array instead.
For example if you're sending a bunch of strings send a String array via SFSObj.putUtfStringArray(key, value);

If the type of these objects is not known, then you can use an SFSArray which accepts any types (among those supported).

You can then cycle on it like this:

Code: Select all

for (int i =0; i < sfsArray.size(); i++)
{
   SFSDataWrapper item = sfsArray.get(i);

   if (item.getTypeId() == SFSDataType.DOUBLE)
   ...
   ...
}


which will allow you to detect the type of each item in the array.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 61 guests