Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby Ninjaoninja2 » 22 Apr 2017, 23:07

Hey guys,

I have ran into a new problem, I cannot convert (293) half of my stage to successfully spawn in my avatars. Any value I give it, it won't let me use. Any ideas? Here's my code:

Code: Select all

if (! sfs.mySelf.containsVariable(this.USERVAR_X) && ! sfs.mySelf.containsVariable(this.USERVAR_Y))
         {
            var px:int = stage.height/2;
            var py:int = stage.width/2;
            setAvatarVariables(px, py);
         }

         function setAvatarVariables(px:int, py:int):void
         {
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby meanvel » 23 Apr 2017, 00:14

You need to provide a user variable formatted properly with a smartFox class, not a number... The problem is in your setAvatarVariables() function, or the next function, not here...

Somewhere you went wrong with these... Are you sure USERVAR_? are all strings? The first input for creating a instance of SFSUserVariable requires a STRING identifier. (Text)

Code: Select all

userVars.push(new SFSUserVariable(this.USERVAR_Y, py));
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby Ninjaoninja2 » 23 Apr 2017, 00:44

meanvel wrote:You need to provide a user variable formatted properly with a smartFox class, not a number... The problem is in your setAvatarVariables() function, or the next function, not here...

Somewhere you went wrong with these... Are you sure USERVAR_? are all strings? The first input for creating a instance of SFSUserVariable requires a STRING identifier. (Text)

Code: Select all

userVars.push(new SFSUserVariable(this.USERVAR_Y, py));

This would be what you're talking about right?

Code: Select all

private const USERVAR_X:String = "x";
private const USERVAR_Y:String = "y";
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby meanvel » 23 Apr 2017, 09:34

Ninjaoninja2 wrote:This would be what you're talking about right?

Code: Select all

private const USERVAR_X:String = "x";
private const USERVAR_Y:String = "y";


Yep, those look correct... What about the code where your creating the user variables? That error says your sending smartFox a number instead of a user variable somewhere.

My suggestion is... When getting started, use a version control program and/or compile and test immediately after you make any changes. Depending upon what your using clientside... For Flash, compiling and testing after each couple changes only takes a second.
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby Ninjaoninja2 » 23 Apr 2017, 13:29

meanvel wrote:
Ninjaoninja2 wrote:This would be what you're talking about right?

Code: Select all

private const USERVAR_X:String = "x";
private const USERVAR_Y:String = "y";


Yep, those look correct... What about the code where your creating the user variables? That error says your sending smartFox a number instead of a user variable somewhere.

My suggestion is... When getting started, use a version control program and/or compile and test immediately after you make any changes. Depending upon what your using clientside... For Flash, compiling and testing after each couple changes only takes a second.

I do test my game after every little code change to see if things change. And I'm not directly feeding SFS numbers, I have stage.height/2 and stage.width/2 and before that I had the code that randomly spawns the user. Both did nothing different, sfs read them as numbers.
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby meanvel » 24 Apr 2017, 03:07

Ninjaoninja2 wrote:I do test my game after every little code change to see if things change. And I'm not directly feeding SFS numbers, I have stage.height/2 and stage.width/2 and before that I had the code that randomly spawns the user. Both did nothing different, sfs read them as numbers.


Well, according to that error code... Something like this is being pushed into your user variables array. I'm kinda bored, so feel free to PM me a link to your source if you want me to take a glance at it.

Code: Select all

var userVars:Array = [];
            userVars.push(293); //This will cause that error code.
            userVars.push(new SFSUserVariable(this.USERVAR_X, px));
            userVars.push(new SFSUserVariable(this.USERVAR_Y, py));
            sfs.send(new SetUserVariablesRequest(userVars));
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby Lapo » 24 Apr 2017, 06:57

Ninjaoninja2 wrote:Hey guys,

I have ran into a new problem, I cannot convert (293) half of my stage to successfully spawn in my avatars. Any value I give it, it won't let me use. Any ideas? Here's my code:

Code: Select all

if (! sfs.mySelf.containsVariable(this.USERVAR_X) && ! sfs.mySelf.containsVariable(this.USERVAR_Y))
         {
            var px:int = stage.height/2;
            var py:int = stage.width/2;
            setAvatarVariables(px, py);
         }

         function setAvatarVariables(px:int, py:int):void
         {


For starters could you show exactly the error you're getting (stacktrace and all)?
Also the code snippet you have posted does not contain any SFS related code, can you point me to the line of code that is causing the error?
Lapo
--
gotoAndPlay()
...addicted to flash games
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby Ninjaoninja2 » 26 Apr 2017, 18:42

Lapo wrote:
Ninjaoninja2 wrote:Hey guys,

I have ran into a new problem, I cannot convert (293) half of my stage to successfully spawn in my avatars. Any value I give it, it won't let me use. Any ideas? Here's my code:

Code: Select all

if (! sfs.mySelf.containsVariable(this.USERVAR_X) && ! sfs.mySelf.containsVariable(this.USERVAR_Y))
         {
            var px:int = stage.height/2;
            var py:int = stage.width/2;
            setAvatarVariables(px, py);
         }

         function setAvatarVariables(px:int, py:int):void
         {


For starters could you show exactly the error you're getting (stacktrace and all)?
Also the code snippet you have posted does not contain any SFS related code, can you point me to the line of code that is causing the error?

Okay, but it doesn't contain anything useful as far as I know anyways. It doesn't give me a line for the error if you'd like to take a look :

Code: Select all

You are connected!
Login Succesfull!
Room joined successfully
TypeError: Error #1034: Type Coercion failed: cannot convert 521 to com.smartfoxserver.v2.entities.variables.UserVariable.
   at com.smartfoxserver.v2.requests::SetUserVariablesRequest/execute()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/requests/SetUserVariablesRequest.as:93]
   at com.smartfoxserver.v2::SmartFox/send()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/SmartFox.as:1767]
   at Function/Main/onJoin/setAvatarVariables()[C:\Users\Zach Harland\Desktop\SPSrc\src\Main.as:95]
   at Main/onJoin()[C:\Users\Zach Harland\Desktop\SPSrc\src\Main.as:86]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at com.smartfoxserver.v2.controllers::SystemController/fnJoinRoom()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:289]
   at com.smartfoxserver.v2.controllers::SystemController/handleMessage()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/controllers/SystemController.as:139]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/dispatchRequest()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:150]
   at com.smartfoxserver.v2.core::SFSProtocolCodec/onPacketRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSProtocolCodec.as:54]
   at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:252]
   at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/core/SFSIOHandler.as:111]
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer.2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:454]
(note the stage size has increased since last time so 521 is the half the stage now.

And here's my full code (IP's been taken out obviously.)

Code: Select all

package
{

   import flash.display.MovieClip;
   import com.smartfoxserver.v2.entities.managers.IRoomManager;
   import flash.events.MouseEvent;
   import com.smartfoxserver.v2.SmartFox;
   import com.smartfoxserver.v2.core.SFSEvent;
   import com.smartfoxserver.v2.core.BaseEvent;
   import com.smartfoxserver.v2.requests.BaseRequest;
   import com.smartfoxserver.v2.entities.data.ISFSObject;
   import com.smartfoxserver.v2.entities.data.SFSObject;
   import com.smartfoxserver.v2.requests.LoginRequest;
   import com.smartfoxserver.v2.entities.Room;
   import com.smartfoxserver.v2.entities.User;
   import com.smartfoxserver.v2.entities.SFSUser;
   import com.smartfoxserver.v2.requests.*;
   import com.smartfoxserver.v2.entities.managers.*;
   import flash.display.DisplayObject;
   import com.smartfoxserver.v2.entities.variables.*;
   import com.smartfoxserver.v2.requests.SetUserVariablesRequest;
   import com.smartfoxserver.v2.entities.managers.IUserManager;
   import com.smartfoxserver.v2.entities.managers.IRoomManager;
   import com.smartfoxserver.v2.entities.User;
   import com.smartfoxserver.v2.entities.Room;


   public class Main extends MovieClip
   {
      var sfs = new SmartFox();
      private const USERVAR_X:String = "x";
      private const USERVAR_Y:String = "y";
      private const AVATAR_SPEED:int = 100;// Expressed in pixels/sec
      private var avatars:Array;
      public function Main()
      {
         
         sfs.addEventListener(SFSEvent.ROOM_JOIN, onJoin);
         sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onJoinError);
         sfs.addEventListener(SFSEvent.LOGIN_ERROR, onLoginError);
         sfs.addEventListener(SFSEvent.LOGIN, onLogin);
         sfs.addEventListener(SFSEvent.CONNECTION, onConnection);
         sfs.addEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost);
         sfs.connect("**.***.***.**", 9933);
         function onConnection(SFSEvent)
         {
            trace("You are connected!");
         }
         function onConnectionLost(evt: SFSEvent)
         {
            trace("Connection Lost!" + evt.params.reason);

         }
         bt_login.addEventListener(MouseEvent.CLICK, onBtLoginClick);

         function onBtLoginClick(evt: MouseEvent):void
         {
            //Login to Login Assitant

            // This code is executed after the connection
            var params: ISFSObject = new SFSObject();
            params.putUtfString("passwd", passWord.text);
            sfs.send(new LoginRequest(userName.text, "", "SP", params));
            sfs.send(new JoinRoomRequest("Town"));

         }
         function onLogin(SFSEvent)
         {
            nextFrame();
            trace("Login Succesfull!");

         }
         function onLoginError(SFSEvent)
         {
            prevFrame();
            trace("login UnSuccesfull!");
         }
      }
      function onJoin(evt:SFSEvent):void
      {
         trace("Room joined successfully");
         if (! sfs.mySelf.containsVariable(this.USERVAR_X) && ! sfs.mySelf.containsVariable(this.USERVAR_Y))
         {
            var px:int = stage.width/2
            var py:int = stage.height/2
            setAvatarVariables(px, py);
         }

         function setAvatarVariables(px:int, py:int):void
         {
            var userVars:Array =[px, py];
            userVars.push(new SFSUserVariable(this.USERVAR_X, px));
            userVars.push(new SFSUserVariable(this.USERVAR_Y, py));

            sfs.send(new SetUserVariablesRequest(userVars));
         }

         function onUserVarsUpdate(evt:SFSEvent):void
         {
            var changedVars:Array = evt.params.changedVars as Array;
            var user;
            this.User = evt.params.user as this.User;

            // Check if the user changed his position
            if (changedVars.indexOf(this.USERVAR_X) != -1 || changedVars.indexOf(this.USERVAR_Y) != -1)
            {
               // Check if avatar exists
               if (this.getAvatar(user.id) != null)
               {
                  // Move the user avatar
                  this.moveAvatar(user);
               }
               else
               {
                  // Create the user avatar
                  this.createAvatar(user, true);
               }
            }
         }

      }

      private function onJoinError(evt:SFSEvent):void
      {
         trace("Room joining failed");
      }


   }
   
}
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby meanvel » 26 Apr 2017, 23:01

You sending numbers, where there should only be instances of SFSUserVariable's...

Code: Select all

            var userVars:Array =[px, py];//Problem is right here.
            userVars.push(new SFSUserVariable(this.USERVAR_X, px));
            userVars.push(new SFSUserVariable(this.USERVAR_Y, py));


//Change that to...
var userVars:Array = new Array();//Should be fixed
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby Ninjaoninja2 » 26 Apr 2017, 23:24

meanvel wrote:You sending numbers, where there should only be instances of SFSUserVariable's...

Code: Select all

            var userVars:Array =[px, py];//Problem is right here.
            userVars.push(new SFSUserVariable(this.USERVAR_X, px));
            userVars.push(new SFSUserVariable(this.USERVAR_Y, py));


//Change that to...
var userVars:Array = new Array();//Should be fixed

This is very strange, after changing that it goes back to saying "Parameter value must be non-null"
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby meanvel » 27 Apr 2017, 02:21

Ninjaoninja2 wrote:
meanvel wrote:You sending numbers, where there should only be instances of SFSUserVariable's...

Code: Select all

            var userVars:Array =[px, py];//Problem is right here.
            userVars.push(new SFSUserVariable(this.USERVAR_X, px));
            userVars.push(new SFSUserVariable(this.USERVAR_Y, py));


//Change that to...
var userVars:Array = new Array();//Should be fixed

This is very strange, after changing that it goes back to saying "Parameter value must be non-null"


Which parameter value is the error message for?
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Cannot convert 293 to com.smartfoxserver.v2.entities.variables.UserVariable.

Postby meanvel » 27 Apr 2017, 02:25

I'm just going to convert your variables to use my code which is working for me... See if this works. If not, the problem is somewhere else...

Code: Select all

        //Position
   var sfsX:UserVariable = new SFSUserVariable("x", px);
        var sfsY:UserVariable = new SFSUserVariable("y", py);
        sfs.send(new SetUserVariablesRequest([sfsX, sfsY]));
       

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 71 guests