Issue with getting data from xtmessage
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Issue with getting data from xtmessage
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!
"thing":[{"one":63}]
I tried doing this:
trace(dataObject['thing']['one'])
It worked well them there weren't any square brackets..
Thanks in advance!
Re: Issue with getting data from xtmessage
In this case the square brackets indicate an array.
So you should probably use:
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
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
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
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.
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
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?
When I connect to the server I get data like my level and other stuff, can I display it with this method?
Re: Issue with getting data from xtmessage
I need an example to understand. Thanks
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
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.
Re: Issue with getting data from xtmessage
It sounds like you have to do this manually? Why?
The client API already deal with that hassle for you
The client API already deal with that hassle for you
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
Um not really, I'm just trying to get the users "level" using the client
Re: Issue with getting data from xtmessage
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
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
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
Sorry I'll explain it better
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
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
Re: Issue with getting data from xtmessage
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
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
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
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"
[ 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"
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
So can I trace that somehow?
Re: Issue with getting data from xtmessage
Well, asked for code not data dumps... anyways.
It looks like you can simply read it via:
where obj is the data object passed to you by the API
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
-
- Posts: 30
- Joined: 25 Aug 2016, 02:52
Re: Issue with getting data from xtmessage
Totally works! thank you very much!
Return to “SmartFoxServer 1.x Discussions and Help”
Who is online
Users browsing this forum: No registered users and 79 guests