Writing your own script
All you have left to do is write the asResultString script, the get selector for the asResultString derived attribute.
Select asResultString in the Script Editor. Replace the generated code with the following script:
asResultString
"Answers a String that shows the total time the runner
took to finish the race and the runner's number"
 
| resultTime resultString |
self finishTime == nil
ifTrue: [resultString := '??:??:??']
ifFalse: [
resultTime := (self finishTime)
subtractTime: (Time new hours: 10 minutes: 0 seconds: 0).
resultString :=
(resultTime hours printStringRadix: 10 padTo: 2),':',
(resultTime minutes printStringRadix: 10 padTo: 2),
':', (resultTime seconds printStringRadix: 10 padTo: 2)].
^resultString, ' - ', (self number).
Notice that you did not need to initialize the finishTime attribute in the finishTime script because you are intentionally checking to see whether it is nil. If finishTime is nil (because the runner has not finished the race), then the resultTime is not yet known. If the runner has finished the race and finishTime is not nil, the resultTime is calculated by subtracting the start time of 10:00:00 from the finish time.
Remember that the finishTime attribute actually holds a Time object, which understands the subtractTime:, hours:minutes:seconds:, hours, minutes, and seconds messages used in this script. Likewise, the hours, minutes, and seconds messages resolve to Integer objects, which understand the printStringRadix:padTo: message used.
Save the script and close the window, because you are finished defining your Runner part.
Tip icon
Learning an object-oriented class hierarchy is often best done through exploration and trial and error. A good class reference is useful, but as you become more experienced, you will find it handy to browse the class hierarchy directly until you find a script that looks like it might do what you need. Reading the actual code and comments of scripts will give you as much, or more, to go on than the information in the class reference. When you find something promising, you can test it either in your code or from a System Transcript.
Last modified date: 07/15/2020