Updating Avatar

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

Moderators: Lapo, Bax

Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Updating Avatar

Postby Nigey » 13 Mar 2015, 11:47

Hi Guys,

I'm trying to update my Characters avatar in my game. My character loads all of his assets (clothing, accessories, ect), from a database and is then stored as as a XML:

Code: Select all

private function onReceivedUserInfo(event:LoaderEvent):void
      {
         
         var raw_user_info = LoaderMax.getContent("userInfo");
         trace("raw user info: " + raw_user_info)
         
         var userInfo:XML = XML(raw_user_info);


That's all working fine. When he goes to edit his character any changes are collected into the XML data. Once the changes are completed, his object is destroyed, recreated, and has his assets re-attach, and placed in the same location. However this is only seen by the local user. I was wondering how to do this for all players.

I see there is 'onUserVarsUpdate', but would that mean I'd need to put in every data field from everyone's XML and add it as a 'smartfox.setUserVariables'? Would it be more feasible to have the player leave and re-enter the room? Or is there a simpler way?

I promise I will stop asking questions soon lol. I'm just getting to grips with SFS first.

Thanks!
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Updating Avatar

Postby Bax » 13 Mar 2015, 13:36

I think you should use the User Variables. You have two options then:
1) split the XML data in multiple variables: this can be a boring process, but the advantage is that in case the user just changes a single property (for example the color of the hairs), only that property is transmitted to all the other users;
2) usa a single User Variable containing the whole xml string; this is super-easy to do, but then you will have to send the full avatar configuration even if small changes are done. This could be a little improved by using JSON instead of XML (save some bandwidth).
Even if you make the player leave and re-enter the map, you will still need a way to let everybody know what the configuration of the avatar is.
Hope this helps.
Paolo Bax
The SmartFoxServer Team
Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Re: Updating Avatar

Postby Nigey » 24 Mar 2015, 10:46

Awesome, thanks Paolo. Which import do I need to access SFSUserVariables?
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Updating Avatar

Postby Bax » 25 Mar 2015, 08:27

com.smartfoxserver.v2.entities.variables package.
Paolo Bax
The SmartFoxServer Team
Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Re: Updating Avatar

Postby Nigey » 25 Mar 2015, 09:46

Hi Bax,

My game isn't recognising that package (Definition com.smartfoxserver.v2.entities:variables could not be found). In OpenSpace Editor, under the 'About OpenSpace' it says the version is 2.0.2, so I'm guessing that's not the issue. when I type in 'com.smartfoxserver.' the only available option is openspace?

Thanks for your help!
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Updating Avatar

Postby Bax » 25 Mar 2015, 10:45

Make sure you also reference the SFS2X AS3 API swc file in your project. You can download it form our website: http://www.smartfoxserver.com/download/sfs2x#p=client
Paolo Bax
The SmartFoxServer Team
Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Re: Updating Avatar

Postby Nigey » 25 Mar 2015, 17:12

I've included it in the 'ActionScript Settings', under 'Library Path'. The API recognises it on auto search now, however when I try to publish it still says 'Definition com.smartfoxserver.v2.entities:variables could not be found'.

Any ideas?
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Updating Avatar

Postby Bax » 27 Mar 2015, 08:46

Is "com.smartfoxserver.v2.entities:variables" a typo or did you actually write it like that in Flash? (the ":" before "variables")
That could be the reason why it is not recognized.
Paolo Bax
The SmartFoxServer Team
Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Re: Updating Avatar

Postby Nigey » 27 Mar 2015, 18:32

Hi Bax,

No it's been done like this

Code: Select all

import com.smartfoxserver.v2.entities.variables;
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Updating Avatar

Postby Bax » 30 Mar 2015, 08:20

I think you are not importing the class in the right way.
You should either use:
import com.smartfoxserver.v2.entities.variables.SFSUserVariable;

or:
import com.smartfoxserver.v2.entities.variables.*;

In fact I started a new Flash project, linked the API swc like you did and created a SFSUserVariable: everything works fine and no compilation errors are thrown.
Paolo Bax
The SmartFoxServer Team
Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Re: Updating Avatar

Postby Nigey » 08 Apr 2015, 09:26

Okay well I've been working through this, but haven't quite understood my problem yet. So far I've managed get it to recognise the v2 now.

This is my current code to set a SFSUserVariable:

Code: Select all

   import com.smartfoxserver.v2.entities.variables.*;
   import com.smartfoxserver.v2.requests.*;
//...
//...
         var userVars:Array = [];
         userVars.push(new SFSUserVariable("pXML", global.pAvatarXMLDat));
         global.smartFox.send(new SetUserVariablesRequest(userVars));


I've done this copying the example here: http://docs2x.smartfoxserver.com/api-docs/asdoc/com/smartfoxserver/v2/requests/SetUserVariablesRequest.html.

Now when I try to play I get a SmartFoxServer error:
TypeError: Error #1010: A term is undefined and has no properties.


Looking at it through Flash Remote Debug UserVars is being recognised as having a length of 0, with the 0 being the XMLDat I made (a short XML doc saying name, age, gender, skin colour, and basic clothes). I can't see why it wouldn't like the SFSUserVariable I've created.
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Updating Avatar

Postby Bax » 08 Apr 2015, 15:36

What type is the global.pAvatarXMLDat object? Keep in mind that the User Variables support the following types: Boolean, int, Number, String, SFSObject, SFSArray.
Maybe you are passing an object of type XML directly?
Paolo Bax
The SmartFoxServer Team
Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Re: Updating Avatar

Postby Nigey » 14 Apr 2015, 10:42

Hi Bax,

I think that would be the exact issue. In that case I'll go ahead and make some individual string values and create SFS variables for each... Will it make any real cost on the server if I make about 8 ish SFS variables per avatar? So long as they're just simple string values for avatars changing clothing and things?..

Thanks!
Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

Re: Updating Avatar

Postby Nigey » 14 Apr 2015, 14:43

I am still getting the same issue though.

Code: Select all

      private function SetSFSUserVars(userXML:XML)
      {
         trace("CALLING SetSFSUserVars===================");
         var userVars:Array = [];
         
         for(var i=0; i < userXML.Msg.avatar.decal.length(); i++)
         {
            userVars.push(new SFSUserVariable("pXML", String(userXML.Msg.avatar.decal[i].filename)) );
            trace("CHECK THIS!!!!: " + userVars + "AND THIS: " + userXML.Msg.avatar.decal[i].filename);
         }
         
         global.sfsUserVars = userVars;
         global.smartFox.send(new SetUserVariablesRequest(userVars);
      }


Still comes up with this issue:

NIGE CALLING SetSFSUserVars===================
CHECK THIS!!!!: [UVar: pXML, type: String, value: mc_male_pants001]AND THIS: mc_male_pants001
CHECK THIS!!!!: [UVar: pXML, type: String, value: mc_male_pants001],[UVar: pXML, type: String, value: mc_face001]AND THIS: mc_face001
CHECK THIS!!!!: [UVar: pXML, type: String, value: mc_male_pants001],[UVar: pXML, type: String, value: mc_face001],[UVar: pXML, type: String, value: mc_female_hair001]AND THIS: mc_female_hair001
CHECK THIS!!!!: [UVar: pXML, type: String, value: mc_male_pants001],[UVar: pXML, type: String, value: mc_face001],[UVar: pXML, type: String, value: mc_female_hair001],[UVar: pXML, type: String, value: mc_male_shirt003]AND THIS: mc_male_shirt003
TypeError: Error #1010: A term is undefined and has no properties.


With the remote debugger the pXML0, pXML1, pXML2, and pXML3 are all of type 'String'. So that's correct. They're generally saying things like mc_male_pants001, and that's it. I'm not quite sure what the issue is now...
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Updating Avatar

Postby Bax » 15 Apr 2015, 08:02

Make sure global.sfsUserVars is not undefined. Also in the code above a ")" is missing at the of the last line (but it should not even compile).
Paolo Bax
The SmartFoxServer Team

Return to “OpenSpace v2 discussions and help”

Who is online

Users browsing this forum: No registered users and 3 guests