I'm new to sfs and I really love it and think its a great program. Like all programs though, it seems to have its odd quirks that I'm trying to figure out. Getting an understanding of a programs quirks is always harder than learning the code.
I've noticed that once in a while:
smartfox.sendObject
just doesn't properly work. For example, when I enter into a room and start a game, an avatar is created in everyone else's game using smartfox.sendObject type of code, but once in a while, this avatar code just gets lost or doesn't go through. When this happens the missing avatar causes the game code to not function properly on all users. Essentially the game freezes up. Is there a way to safeguard against this? I can put in long complicated codes that check to make sure everything is where it should be, but this seems like such a hassle. is there some way to get confirmation back that the sendObject is received or something?
Again this only happens about 1 in every 20 times. Perhaps your experts can tell me if this is a quirk or if it is more likely that my coding is just bad and I need to reexamine my code because this should never happen.
thanks
Jason
smartfox.sendObject quirks
-
starvingeyes
- Posts: 17
- Joined: 25 Oct 2007, 05:50
- Carl Lydon
- Posts: 298
- Joined: 12 Nov 2007, 16:15
- Location: NYC
Maybe...
I personally hate it when I ask how to do something and instead of telling me they suggest I do something completely different... but....
Instead of using sendObject to create avatars when you enter a room, you could...
1. Have your avatar information inside user variables
2. When you enter a room, you get the room object
3. Inside the room object you have a userlist (including yours)
4. Inside each user list, in the user variables, you get your avatar info
5. Build all your avatars based on this info
For users already in the room, they will get the "onUserEnterRoom()" event from which they can extract the user name and avatar variables.
I think that the "onJoinRoom()" and "onUserEnterRoom()" are always going to fire for you so you should never miss a user entrance. Also, this is much more efficient than each user asking and telling every other user what it's info is; the server can keep track of this and only send it out to the users that need it.
As for the SendObj problem; I'm also sort of new, but it could be that 2 objects are received at the same time and only the last one is taken? There's a que for that, right?
Instead of using sendObject to create avatars when you enter a room, you could...
1. Have your avatar information inside user variables
2. When you enter a room, you get the room object
3. Inside the room object you have a userlist (including yours)
4. Inside each user list, in the user variables, you get your avatar info
5. Build all your avatars based on this info
For users already in the room, they will get the "onUserEnterRoom()" event from which they can extract the user name and avatar variables.
I think that the "onJoinRoom()" and "onUserEnterRoom()" are always going to fire for you so you should never miss a user entrance. Also, this is much more efficient than each user asking and telling every other user what it's info is; the server can keep track of this and only send it out to the users that need it.
As for the SendObj problem; I'm also sort of new, but it could be that 2 objects are received at the same time and only the last one is taken? There's a que for that, right?
-
starvingeyes
- Posts: 17
- Joined: 25 Oct 2007, 05:50
thanks Carl. That probably is a better way to deal with avatars. It seams that you've answered my main question which is whether sendObject is just quirky or whether my code is just bad...it seams you think it can be quirky.
This also happens when I have my avatars in my turn based game doing moves though (which also happens with sendObject). Is there some kind of a code that could prevent the 2 sendObjects like you say from being received at the same time and one not happening? somthing like isBusy or something?
anybody else have any thoughts or help on this?
This also happens when I have my avatars in my turn based game doing moves though (which also happens with sendObject). Is there some kind of a code that could prevent the 2 sendObjects like you say from being received at the same time and one not happening? somthing like isBusy or something?
anybody else have any thoughts or help on this?
- Carl Lydon
- Posts: 298
- Joined: 12 Nov 2007, 16:15
- Location: NYC
I'll look
I'm going to look into this because I use SendObject for allot of things, too. I think the best course of action for either of us is to check some of the example files for SendObj, and see if it uses anything like the "evtQueue", with the "onRoomListUpdate":
_global.isBusy = false;
var evtQueue = [];
//----------------------------------------------------------
// Handle the onRoomListUpdate here and keep it in the queue.
//----------------------------------------------------------
smartFox.onRoomListUpdate = function(o) {
evtQueue.push(o);
};
It might be that you get 2 events while on the same frame. Are you sure that you're not receiving the object at all? Are you doing a "trace" for each time you receive an object to check? Maybe you're client isn't capruring new users entering the room, and these are the avatars that you're not getting?
_global.isBusy = false;
var evtQueue = [];
//----------------------------------------------------------
// Handle the onRoomListUpdate here and keep it in the queue.
//----------------------------------------------------------
smartFox.onRoomListUpdate = function(o) {
evtQueue.push(o);
};
It might be that you get 2 events while on the same frame. Are you sure that you're not receiving the object at all? Are you doing a "trace" for each time you receive an object to check? Maybe you're client isn't capruring new users entering the room, and these are the avatars that you're not getting?
- Carl Lydon
- Posts: 298
- Joined: 12 Nov 2007, 16:15
- Location: NYC
As far as we can say there's really no problem with the sendObject method.When this happens the missing avatar causes the game code to not function properly on all users. Essentially the game freezes up. Is there a way to safeguard against this?
What I would recommend is to try to isolate the problem with fewer clients possible ( 2-3 ) and see if there's a way to reproduce it consistently.
One possible cause of this problem is frame synchronization. As Carl suggested, if you're skipping frames in the time between the request and the response, you might loose the event not because the server is not sending it but because the client isn't ready to "capture it" yet