||unity-dev|| Holiday help!

Discussion list for Unity developers. unity-dev at moock.org
Wed Dec 20 23:02:32 CST 2006


hi ryan,
as jose already suggested, you should implement the four 
"button-selected" states using a room attribute. assuming you already 
have a chat room functional, and you have an object registered for 
events from that room, you can call URoom.setAttributeOnServer() to set 
your attribute, and then implement URoomListener.onUpdateRoomAttribute() 
in your event-handling class to respond to changes in the attribute.

your attribute-setting code might look like this:
yourRoom.setAttributeOnServer("selectedButton", "3", true)

and your event-handling code might look like this:
public function onUpdateRoomAttribute (e:URoomEvent):Void {
   if (e.getChangedAttr().attrVal == "1") {
     // Display button-one-selected state
   }
   // ...etc
}

here's more info from the docs:

=====
setAttributeOnServer

public function setAttributeOnServer(attrName:String, attrValue:String, 
isShared:Boolean, isPersistent:Boolean, appendVal:Boolean):Void

Asks Unity to set an attribute for this room. An attribute is simply a 
named piece of information stored by the room on the server, much like a 
variable, with the added benefit that it can be automatically shared 
with all clients in the room. Room attributes are intended to store 
information about the room's environment, such as the highscore in a 
game room or perhaps the position of the furniture in a virtual house.

If setAttributeOnServer() is called with isShared set to true, then the 
attribute value is automatically propagated to all clients in the room 
on which the attribute is set. Clients can respond to the changing of a 
shared room attribute value via the 
URoomListener.onUpdateRoomAttribute() event. Clients can only set 
attributes on rooms they are in.
======

colin


Discussion list for Unity developers. wrote:
> Hello,
> 
> I am trying to incorporate Unity into my web app for work. We are a  
> non-profit lab and our group is just myself and one other semi- 
> developer. Can someone please help me?
> 
> Here is the scenario: Each person logged in has a view of a screen  
> with 4 buttons on it. When one user selects a button, it becomes  
> selected on everyone else's screen. If another user changes the  
> selection, everyone's is changed. I was thinking of using a "room  
> variable" to do this. But between the listeners and the local  
> variables, I am lost.
> 
> Here is my code... I need to hook up something like the chat window  
> listener so that when I select a button, it sets a room variable  
> called "whichButtonIsSelected" and some way of having everyone else's  
> screen constantly check to see the state of that variable.
> 
> Is this the right way to do it? I am stuck... and the documentation  
> and examples works fine for chat, but not for much more.
> 
> Thank you so much for your help,
> 
> Ryan
> Cambridge, MA
> 
> 
> import mx.skins.RectBorder;
> import mx.core.ext.UIObjectExtensions;
> 
> 
> 
> // Listen for send Button clicks.
> send.clickHandler = function (e:Object):Void {
>    sc.sendMessage();
> }
> 
> 
> // ////////////////////////////////////////////////////////////////////
> 
> // Listen for 4 Button clicks.
> option0.clickHandler = function (e:Object):Void {
>    sc.setCurrentButton(this);
> }
> option1.clickHandler = function (e:Object):Void {
>    sc.setCurrentButton(this);
> }
> option2.clickHandler = function (e:Object):Void {
>    sc.setCurrentButton(this);
> }
> option3.clickHandler = function (e:Object):Void {
>    sc.setCurrentButton(this);
> }
> 
> // ////////////////////////////////////////////////////////////////////
> 
> 
> 
> // Listen for enter key presses in outgoing.
> var outgoingEnterHandler:Object = new Object();
> outgoingEnterHandler.enter = function (e:Object):Void {
>    sc.sendMessage();
> };
> outgoing.addEventListener("enter", outgoingEnterHandler);
> 
> // Listen for setName Button clicks.
> setName.clickHandler = function (e:Object):Void {
>    sc.setName();
> }
> 
> // Listen for enter key presses in nameInput.
> var nameInputEnterHandler:Object = new Object();
> nameInputEnterHandler.enter = function (e:Object):Void {
>    sc.setName();
> };
> nameInput.addEventListener("enter", nameInputEnterHandler);
> 
> 
> //var currentButton:String = "option0";
> //option0.setStyle("themeColor", "haloOrange");
> //option0.setStyle("emphasized", "true");
> //trace("Current selection is on " + currentButton);
> 
> 
>   
> --
> you're a unity-dev subscriber. to unsubscribe, visit www.moock.org/mailman/listinfo/unity-dev/
> 
> superb hosting for this list and moock.org is generously provided by Rackspace. See: http://www.rackspace.com/?supbid=moock


More information about the unity-dev mailing list