Avatar reloading after map saving

Post here your questions about the OpenSpace 2.x or notify bugs and suggestions.

Moderators: Lapo, Bax

cyli
Posts: 16
Joined: 09 Mar 2010, 18:39

Avatar reloading after map saving

Postby cyli » 06 Apr 2010, 04:43

I am experiencing an error where, after editing the map, saving, and reloading, I get this error when openspace wants to recreate the avatars:

Code: Select all

[OpenSpace|ERROR] (0600) Invalid map coordinates passed during avatar creation, or wrong map access point coordinates
Error: No access point available in current map
   at com.smartfoxserver.openspace.engine.control::IsoEngineController/validateAvatarCreationPosition()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/OpenSpace/Client/Classes/src/com/smartfoxserver/openspace/engine/control/IsoEngineController.as:2047]
   at com.smartfoxserver.openspace.engine.control::IsoEngineController/validateAvatarCreation()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/OpenSpace/Client/Classes/src/com/smartfoxserver/openspace/engine/control/IsoEngineController.as:799]
   at com.smartfoxserver.openspace.engine.control::OpenSpaceController/createMyAvatar()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/OpenSpace/Client/Classes/src/com/smartfoxserver/openspace/engine/control/OpenSpaceController.as:774]
   at com.smartfoxserver.openspace.engine.control::OpenSpaceController/onExtensionResponse()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/OpenSpace/Client/Classes/src/com/smartfoxserver/openspace/engine/control/OpenSpaceController.as:1540]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at it.gotoandplay.smartfoxserver.handlers::ExtHandler/handleMessage()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/handlers/ExtHandler.as:64]
   at it.gotoandplay.smartfoxserver::SmartFoxClient/jsonReceived()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/SmartFoxClient.as:2644]
   at it.gotoandplay.smartfoxserver::SmartFoxClient/handleMessage()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/SmartFoxClient.as:2980]
   at it.gotoandplay.smartfoxserver::SmartFoxClient/handleSocketData()[/Users/user/gotoAndPlay/gotoAndPlay/SmartFoxServer/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/SmartFoxClient.as:2954]


However, the avatar was in a valid location before, and the change to the map involved removing an obstacle that was far away from the avatar's location. Upon reloading, the avatar appears in the correct location without any errors. Spawning another in that exact location does not cause an error either.

I've tried removing the user (an NPC) corresponding to that avatar from the room, and and sending them back, but I still get this error.

Any hints as to what may be causing this problem?

Edit/Addendum: My current workaround is to simply disconnect the existing npcs and respawn new npcs with the exact same skin at the exact same location. This is not exactly ideal, though, and I would greatly appreciate any advice.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 06 Apr 2010, 07:10

As the error message says, it seems you have no access points defined for the map. When avatars are recreated after saving the map, the engine tries to place them on an access point, without being able to find it.
The reason is that previous avatar coordinates might be invalid after the map editing, while access points are always valid because they can't be removed during editing.
Paolo Bax
The SmartFoxServer Team
cyli
Posts: 16
Joined: 09 Mar 2010, 18:39

Postby cyli » 06 Apr 2010, 07:32

Thanks!
cyli
Posts: 16
Joined: 09 Mar 2010, 18:39

Postby cyli » 06 Apr 2010, 21:47

I am now no longer getting that error, but the avatar does not respawn (when I look at the room with the admin tool, the npc user is still there, but the _os_px, _os_py, and _os_pz user variables have all been removed).

I've tried re-sending the _os_px, _os_py, and _os_pz variables in the overriden OpenSpaceExtension saveMapData method, and the client seems to receive them (they don't seem to have been changed yet at that point). However, it looks like the position user variables are removed after the saveMapData method is called, since if I print some debugging info in that method, my logs look like this:

Sending avatar to correct coordinates
17:53:25.643 - [ INFO ] > [OpenSpace] Map 'sampleMap' update confirmation sent to user test_user [1] and reload event sent to other users in the same room

I'm currently scheduling resending the position user variables in a timer, but is there a better way to do this? Receive the openSpace events that get sent to my NPC, for instance?
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 07 Apr 2010, 19:00

To me it is not clear what you are trying to do. Maybe you can post the steps (which users/NPC login, when, who updates the map, what should happen then, etc).
Anyway I suggest you to check (by looking at the messages the client receives) how a regular user on the client works (not an NPC). Then you should be able to do the same with an NPC.
Paolo Bax
The SmartFoxServer Team
cyli
Posts: 16
Joined: 09 Mar 2010, 18:39

Postby cyli » 08 Apr 2010, 03:07

Sure. I am making an openspace room competely populated with NPC avatars. The user (1 to a room) will be more of an observer than anything else, although they can edit maps.

When they edit the map, all the NPC avatars disappear.

So for instance, if this is the setup:
1) User logs in, a room is created for them with an empty map, populated by 3 NPC avatars walking around.
2) The user goes into edit mode and puts down a square of grass somewhere in the middle of the room.
3) The user exits edit mode.

From what I can tell from watching messages to/from the client, when the user goes into edit mode the client sends a message to saying that they've gone into edit mode. When they leave edit mode they send a message to the openspace extension detailing their map changes, and openspace saves the map and sends them a reload event.

Afterwards, none of the NPC avatars seem to redraw. When I look at the admin tool, the SmartFoxServer Users of those NPCs are still in the room, but their "_os_x", "_os_y", and "_os_z". I assume that these variables were cleared out, because the user may have placed something on top of where they were.

However, in my situation, let's say for testing purposes I stand the NPCs all in one corner. I place a chair in the opposite corner of the map. I even override the saveMapData method so that when that happens I also go through and remove any NPC that is standing on a now-occupied tile. However, the NPCs still do not reappear when the map reloads, and the position user variables seem to have been cleared out as far as I can tell using the admin tool.

They do not reappear unless I send a position update (ExtensionHelper.instance().setUserVariables with the _os_x, _os_y, _os_z variables).

I'd like to know if there is a way to make them reappear in their previous positions (if they are still valid) without sending this update, or if not, how to know when to send the update (without just setting a timer).

Thanks!

Edit: (I notice that if I just make a client avatar, it reappears on a random access point. The npc avatars do not, however, and at any rate I actually want them to appear elsewhere.)
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 12 Apr 2010, 16:43

Suppose you have avatars A, B and C, where A and B correspond to actual users, and C is an NPC.
If A edits the map and then saves it, the client of user B receives an event which freezes the interaction and tells him to reload the map. Upon reloading, his position uservars are reset, until the client sets them again when the createMyAvatar method is called (using the passed coordinates or getting an access point randomly).
In case of the NPC, you don't have a client receiving that reload event and reacting to it. Not sure how you can obtain what you need to do... I suspect recreating the NPC avatar in the overridden saveMapData method won't work. Maybe you can give it a try.
Paolo Bax
The SmartFoxServer Team
cyli
Posts: 16
Joined: 09 Mar 2010, 18:39

Postby cyli » 14 Apr 2010, 05:41

I cannot detect the client reload event, so I set a timer to resend all the user variables about 500ms after saveMapData is called.

This is not ideal, as if it takes longer than 500ms between saveMapData and the client reload event, the NPCs do not reappear.

I suppose the client can send a message once it receives the reload event...
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 16 Apr 2010, 07:14

We made an improvement to the server-side extension, as described in the OpenSpace 2 final release announcement. Thank you for the feedback.

Now you can listen to the onMapUpdated server-side event. In order to to this you have to:
1) create a class which implements the com.smartfoxserver.openspace.utils.IOpenSpaceEventsListener interface. At the moment it just contains the onMapUpdated method (you can have a separate class to handle events, or you can make your extension implement that interface directly);
2) call the OpenSpaceExtension.setEventsListener passing a reference to the class extending the above interface;
3) in your implementation of the onMapUpdated method, recreate the NPCs, or simply set their user variables.
Paolo Bax
The SmartFoxServer Team

Return to “OpenSpace v2 discussions and help”

Who is online

Users browsing this forum: No registered users and 8 guests