What's New in Director 8.5 > Using the Shockwave Multiuser Server and Xtra > Using databases > Storing information |  |

Storing information

Once you have decided what types of objects to use, it is time to store your data. You start by creating a new object, and then you add attributes to the object. The attributes will be whatever items of information you want to store, such as an e-mail address or a high score. As with other server functions, these operations are performed by sending commands to the server in the `#recipient` parameter of a `sendNetMessage()` and indicating which type of object you want to create or edit.

Keep in mind that you can set different combinations of attributes for different objects. You could assign user Bob `#email` and `#favoriteFood` attributes but assign user Mary `#email` and `#favoritePlace` attributes. What attributes you define and the information you put into them is up to you and what you want your movie to do. Object attributes can contain any Lingo value you wish to store.

You might want to start by storing user-specific information in a `DBUser` object. Since the `DBUser` object for the new user does not yet exist, you must tell the server to create it for you. This is one of several administrative functions you can perform on the server by specifying `DBAdmin` as the object of your command. To create a new `DBUser` object for a new user, use `createUser` in conjunction with `DBAdmin`:

    errCode = gMultiuserInstance.sendNetMessage("system.DBAdmin.createUser", "anySubject", [#userID: "Bob", #password: "MySecret", #userlevel: 20])

This creates a new `DBUser` object with a `#userID` property of Bob.

To add new information to the new user's `DBUser` object, you must name the information, which becomes an attribute of the user. If you are storing e-mail addresses, you could call the attribute `#email`. The attribute name should be a symbol preceded by the `#` sign. You declare a new attribute by using `declareAttribute` with the `DBAdmin` object. Once an attribute has been declared, its name may be used with any of the database object types.

    errCode = gMultiuserInstance.sendNetMessage("system.DBAdmin. declareAttribute", "anySubject", [#attribute: #email])

Now the attribute named `#email` has been declared and may be set for any of the objects you create. To set the e-mail address in the database that was created earlier for the user Bob, use `setAttribute` with the `DBUser` object:

    errCode = gMultiuserInstance.sendNetMessage("system.DBUser.setAttribute", "anySubject", [#userID: "Bob", #attribute: [#email: "bobsmith@companyname.com"]])

The `#content` parameter of this `sendNetMessage()` is a nested property list containing the parameters for the `setAttribute` command. The `#userID` property tells the server which user's information is being edited. The `#attribute` property indicates which attributes are being set and is followed by a list of attributes and values. In this case, only one attribute is being set.

To create a `DBApplication` object and set its attributes, you start by creating a new object, using `createApplication`, and then declaring the attributes you want to use for the object. You then place information into those attributes with `setAttribute`. You add attributes to a `DBPlayer` object by supplying both `#userID` and `#application` properties with `setAttribute`. See Multiuser Lingo Dictionary overview for detailed examples of these.

To construct `DBApplicationData` objects, you put all the data you want them to hold in the form of lists of attributes and then write them to the server as an administrator-level user with `createApplicationData`.

This Lingo statement creates a `DBApplicationData` object containing values that describe a room in an online casino:

    errCode = gMultiuserInstance.sendNetMessage("system.DBAdmin. createApplicationData", "anySubject", [#application: "Casino", #attribute: [#roomName: "BlackJack", #dealerName: "Larry", #wallArt: "Mona Lisa", #minimumBet: 50, #music: "Classical"]])

Subsequent Lingo statements might create additional `DBApplicationData` objects with the attributes for additional rooms in the casino.

Once you have placed the objects on the server, you retrieve them for use in the movie by using `getApplicationData`. This command returns the list of attributes and values for the object that matches the criteria you specify for the current application. To retrieve the `DBApplicationData` object you previously created, you would specify the attribute `#roomName` and the string BlackJack as the search criteria. You supply the string in the `#text` property.

    errCode = gMultiuserInstance.sendNetMessage ( "system.DBApplication.getApplicationData", "anySubject", [#application: "Casino", #attribute: "#roomName", #text: "BlackJack"] )

In addition to the attributes you define, `DBUser`, `DBPlayer`, and `DBApplication` objects each have their own default attributes that are assigned by the server. There are no default attributes for `DBApplicationData` objects.

`DBUser` objects include these attributes:

#userID must be unique.

#password can be accessed with `getAttribute` and `setAttribute`, but only by users with an appropriate user level.

#lastLoginTime is changed by the server each time a user logs in and can be edited by an administrator-level user. See Configuring the server for more information.

#status can be written only by administrators and can be used for whatever purposes you see fit. You might use this to keep track of whether a customer's balance is due or paid in full for a site membership subscription.

#userlevel determines privileges based on the levels you define in the server's configuration file. See Configuring the server. This attribute may be changed only by administrators.

#lastUpdateTime allows you to check whether other users have changed an attribute since you last checked it. This is identical to the way this is used with group attributes. See Working with group attributes.

`DBPlayer` objects include default attributes of `#creationTime` and `#lastUpdateTime`. The `#creationTime` attribute indicates when the object was created on the server and will usually correspond to when the user began participating in a particular movie.

`DBApplication` objects include default attributes of `#userID`, `#description`, and `#lastUpdateTime`. The `#userID` attribute defaults to the name of the movie that created the object, which you supplied in the `connectToNetServer()` command. The `#description` attribute contains whatever description you choose to supply when you create the `DBApplication` object.