In the scripts cast, double-click to open the Main Script movie script so that you can add the following code to the startMovie handler.
_global.myDB = new(xtra "arca")
err = _global.myDB.openDB(_movie.path & "exercise")
errCode = err.errorMsg
if errCode = 604 then
makeDB()
else if errCode <> 0 then
showError(errCode)
end if
Add the code after the Lingo currently in the handler that sets up the other global variables. First, Arca is instantiated into the myDB global variable. In the next line, the openDB() method of the Xtra is used to try and open the database named exercise located in the same folder as the movie. The result of this operation is returned, in a property list form, to the local variable err.
Note The Lingo _movie.path returns the path to the Director movie on your hard drive. Using _movie.path is a good way to place files, such as the database file, in the same folder as your movie. Having the result of the openDB operation returned in a property list is a function of how the Arca Xtra works. Considering that you have yet to create the exercise database, calling the openDB method on it is going to produce an error, which will be returned in the property list to the err variable, as shown.
err = [#errorMsg: 604]
As you may recall from using property lists when creating a getPropertyDescriptionList handler, property lists store their data in a property:value pair. In Lingo you can access the value of the property using dot notation, and the property name as is done in the next line of the code.
the_value = property_list.property_name
errCode = err.errorMsg
When this executes, the local variable errCode will contain whatever numeric error code is returned in the property list. Note that if no error occurs, the error code will be 0, but the property list is still returned. Next, an if statement tests to see if the errCode is 604 and calls the makeDB method if it is. If the error is not 604 then the else statement is executed, which does a further to check to see if errCode is anything but 0. If the errCode is not 0 then the showError method is called, with errCode being sent as a parameter. Many error codes can be generated by the Xtrathey can be found in the documentationbut error code 604 specifically means, "Can not find the database file." If the database file can't be found, you can assume it hasn't been created yet, so a call to the makeDB method is madewhich you will write next, along with the showError method. |