How to broadcast effects of setMyAvatarState to other client

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

Moderators: Lapo, Bax

Madhav
Posts: 78
Joined: 27 Nov 2012, 04:41

How to broadcast effects of setMyAvatarState to other client

Postby Madhav » 14 Feb 2013, 07:48

Hi,
I want to make my avatar wave at other users on clicking a wave button, So I am doing this by changing its state to wave. But the when my avatar waves at others only i can see the waving and it is not being broadcasted to the other clients on the room. So the coding part i am using is simple and as follows...,

var avatarState:Object = {};
avatarState.id = "wave";

var myAvatar:Avatar = openSpace.getMyAvatar();
myAvatar.state = avatarState;

// Change state
openSpace.setMyAvatarState(avatarState);

please help... :(
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: How to broadcast effects of setMyAvatarState to other cl

Postby Bax » 14 Feb 2013, 09:56

You don't need to assign the state manually like you do with these lines of code:

Code: Select all

var myAvatar:Avatar = openSpace.getMyAvatar();
myAvatar.state = avatarState;

The following method call (setMyAvatarState) will do it for you and broadcast the change to the other clients.
Please notice that this will work only if you override the state property on the avatar class. Check the setMyAvatarState documentation.
Paolo Bax
The SmartFoxServer Team
Madhav
Posts: 78
Joined: 27 Nov 2012, 04:41

Re: How to broadcast effects of setMyAvatarState to other cl

Postby Madhav » 14 Feb 2013, 11:44

Thanks a lot Bax got it solved,
Got one more problem i.e when i am changing avatar state the set state function is called twice!!!??
Here's my getter and setters,

override public function get state():Object
{
return _state;
}

override public function set state(data:Object):void
{
_state = data;

if(_state!=null)
if(_state.id == "wave")
{
trace("wave"); //tracing twice???
wave= true;
drawAvatar();
}
}

And as you suggested myStateChange function is,

// Crete action object
var avatarState:Object = {};
avatarState.id = "wave";

// Change state
openSpace.setMyAvatarState(avatarState);

thanks again...
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: How to broadcast effects of setMyAvatarState to other cl

Postby Bax » 14 Feb 2013, 15:49

That might be called twice due to the state UserVariable update event being received back.
Nothing to worry about.
Paolo Bax
The SmartFoxServer Team
Madhav
Posts: 78
Joined: 27 Nov 2012, 04:41

Re: How to broadcast effects of setMyAvatarState to other cl

Postby Madhav » 15 Feb 2013, 04:29

Thanks Bax,
But the thing I am worried about is the wave animation is happening twice... which I don't really want!!!

Any solutions??? :)
Madhav
Posts: 78
Joined: 27 Nov 2012, 04:41

Re: How to broadcast effects of setMyAvatarState to other cl

Postby Madhav » 15 Feb 2013, 07:11

hai...
I am back here with some queries,
When i used setMyAvatarAction for avatar to perform wave action it worked perfectly fine without any issues....
So my question is will there be any issue later!? I am really confused regarding which function to use for avatar to make wave action either setMyAvatarState or setMyAvatarAction!!!!

Please guide....
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: How to broadcast effects of setMyAvatarState to other cl

Postby Bax » 15 Feb 2013, 08:55

Both setMyAvatarAction and setMyAvatarState work in the same way.
The first one is intended for those actions which last a limited amount of time. For example in my opinion waving is an action, because the user clicks a button, the avatar waves for a couple of seconds and the stops.
The state should be something different, its change always controlled by the user: for example making the avatar sit on a chair. When the avatar is seated, its state is changed. Then the user clicks again and the avatar stands up, changing its state.
Hope this helps.
Paolo Bax
The SmartFoxServer Team
Madhav
Posts: 78
Joined: 27 Nov 2012, 04:41

Re: How to broadcast effects of setMyAvatarState to other cl

Postby Madhav » 15 Feb 2013, 09:11

This info was a lot useful for me....
Thanks a lot Bax for your support... :D

Return to “OpenSpace v2 discussions and help”

Who is online

Users browsing this forum: No registered users and 13 guests