What's New in Director 8.5 > Using the Shockwave Multiuser Server and Xtra > Using groups > Defining groups

 

Defining groups

When users connect to the server, they are automatically added to the group @AllUsers for the movie they are using. This lets you easily send messages to everyone connected to the movie without having to create a new group and have everyone join it individually.

You create a new group by having one or more connected users send a message to the server specifying group as the object and join as the command in the recipient parameter of a sendNetMessage() and sending the new group name in the #content parameter. If the group does not exist when the first user joins, the server creates the group for you. Once the group has some members, you can ask the server for the number of members in the group, for a list of the members, or for any attributes that have been assigned to the group.

Once a movie has connected a user to the server, the user can join an existing group by sending a message to the server specifying group as the object and join as the command in the recipient parameter of a sendNetMessage() and sending the group name in the #content parameter. The following message joins a user to the group called @RedTeam.

errCode = gMultiuserInstance.sendNetMessage("system.group.join", "anySubject", "@RedTeam")

It is important that all your group names begin with the @ symbol. The server uses this symbol to distinguish group names from user names when routing standard messages like this one:

errCode = gMultiuserInstance.sendNetMessage("@RedTeam", "Status Update", "Your team is winning.")

If the recipient were simply RedTeam, the server would attempt to find the user named RedTeam instead of the group. No error message is generated when a user is not found by the server.

You can leave a group by specifying system.group.leave in the recipient parameter of a sendNetMessage() and indicating which group you want to leave in the #content parameter:

errCode = gMultiuserInstance.sendNetMessage("system.group.leave", "anySubject", "@RedTeam")

You can determine how many users are in a group by using getUserCount. For example, you can keep team sizes even as more users join a game by adding users to whichever team has a smaller number of players. Or you could create a new group when an existing one exceeds a certain number of users.

errCode = gMultiuserInstance.sendNetMessage("system.group.getUserCount", "anySubject", "@RedTeam")

If you want to get a list of the users in a group, use getUsers:

errCode = gMultiuserInstance.sendNetMessage("system.group.getUsers", "anySubject", "@RedTeam")