Issue with getting data from xtmessage

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Issue with getting data from xtmessage

Postby ProgramBoy » 15 Sep 2016, 19:48

When I try tracing something from a packet that looks like this:

"thing":[{"one":63}]

I tried doing this:

trace(dataObject['thing']['one'])

It worked well them there weren't any square brackets..

Thanks in advance!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue with getting data from xtmessage

Postby Lapo » 16 Sep 2016, 15:06

In this case the square brackets indicate an array.

So you should probably use:

Code: Select all

trace(dataObject['thing'][0]['one'])


You get the array with name "thing", get the first element (index = 0) which is an object and finally get the value for the key "one" in that object.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 16 Sep 2016, 18:04

Lapo wrote:In this case the square brackets indicate an array.

So you should probably use:

Code: Select all

trace(dataObject['thing'][0]['one'])


You get the array with name "thing", get the first element (index = 0) which is an object and finally get the value for the key "one" in that object.

cheers


Thank you for responding! :)

I tried doing this, but it returned an error:

Code: Select all

TypeError: Error #1010: A term is undefined and has no properties.


By the way, when I trace only ['thing'] it returns this:
[object Object]

EDIT:
Nevermind! works perfectly.
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 17 Sep 2016, 21:26

One more question:

When I connect to the server I get data like my level and other stuff, can I display it with this method?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue with getting data from xtmessage

Postby Lapo » 19 Sep 2016, 07:42

I need an example to understand. Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 20 Sep 2016, 14:57

I don't have an example as for now, but from what I know when you send the joinRoom function it gives you back a lot of data. for some reason I couldn't display the data that is in there.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue with getting data from xtmessage

Postby Lapo » 20 Sep 2016, 15:25

It sounds like you have to do this manually? Why?
The client API already deal with that hassle for you :)
Lapo

--

gotoAndPlay()

...addicted to flash games
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 21 Sep 2016, 19:03

Um not really, I'm just trying to get the users "level" using the client ;)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue with getting data from xtmessage

Postby Lapo » 22 Sep 2016, 06:52

Sorry I don't know what a "user level" is exactly?
Again, if you could show us an example of the kind of data you're sending and how you're dealing with it from client side ... it would help us to help you :)
Lapo

--

gotoAndPlay()

...addicted to flash games
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 22 Sep 2016, 12:13

Sorry I'll explain it better :D

When you connect to the server using the client everything is fine, then you get the roomList, and then you join the room
When the server detects that you've joined the room it sends the client some JSON data (it says RECEIVED: {jsondata:here})
In the data it receives stuff like the players level etc

I need to display that data, but for some reason when I try tracing it it says it's a null
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue with getting data from xtmessage

Postby Lapo » 22 Sep 2016, 13:47

Sorry mate, I need code to help you :)
A description of what the code is supposed to do is not going to help.

Show me the server code that sends the data and the relative bit on the client that reads it.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 22 Sep 2016, 18:19

This is the part I need to get data from (Client Side Output):

[ RECEIVED ]: <msg t='sys'><body action='joinOK' r='1007'><pid id='0'/></body></msg>, (len: 165)
[ RECEIVED ]: {"t":"xt","b":{"r":-1,"o":{"level":52}}}

This is what I receive from the server ^
I need to somehow trace "level" :P
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 27 Sep 2016, 13:54

So can I trace that somehow?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Issue with getting data from xtmessage

Postby Lapo » 27 Sep 2016, 14:12

Well, asked for code not data dumps... anyways.
It looks like you can simply read it via:

Code: Select all

var level = obj.level


where obj is the data object passed to you by the API
Lapo

--

gotoAndPlay()

...addicted to flash games
ProgramBoy
Posts: 30
Joined: 25 Aug 2016, 02:52

Re: Issue with getting data from xtmessage

Postby ProgramBoy » 27 Sep 2016, 16:15

Totally works! thank you very much! :D

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 28 guests