WATask and implement the
#go method:
WATask subclass: #GuessingGameTask instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'SCSeasideTutorial' go | number guess | number := 100 atRandom. guess := (self request: 'Enter your guess') asNumber. [guess = number] whileFalse: [guess < number ifTrue: [self inform: 'Your guess was too low'] ifFalse: [self inform: 'Your guess was too high']. guess := (self request: 'Enter your guess') asNumber]. self inform: 'You got it!'Notice that unlike the components we've developed, this class has no
renderContentOn: method, just go. Its
purpose for existing is to move the user through a sequence of steps.
Register it as the root of an application and try it out.
In some sense, tasks are simply components that start their life in
a callback. Tasks are indeed components (WATask is a
subclass of WAComponent) so all of the facilities
available to components, such as call: and
answer:, are available to tasks as well. Tasks, however,
do not render themselves (don't override renderContentOn:
in your tasks), their purpose is simply to sequence through other
views.
PersonalInformationView and then displays
HelloWorldComponent. If you want to get fancy you
could experiment with a login sequence using
WALoginDialog. That is, write a task that requires
the user to log in before proceeding on to another component.In our guessing game it would be nice if the user couldn't back up
and re-submit a guess since this might mess up our count of incorrect
guesses (exercise 1 above). The WAComponent>>isloate:
method takes a block argument prevents backtracking from outside the
block back into the block. Try using the back button in this version
of our game:
go | number guess | number := 100 atRandom. self isolate: [guess := (self request: 'Enter your guess') asNumber]. [guess = number] whileFalse: [guess < number ifTrue: [self inform: 'Your guess was too low'] ifFalse: [self inform: 'Your guess was too high']. self isolate: [guess := (self request: 'Enter your guess') asNumber]]. self inform: 'You got it!'Notice that once you leave an isloated block, you cannot press the back button to back up into that block again. If there were multiple
call:'s in the isolate block, the user would be free to
move back and forward between those but once they step out of the
block they can't move back into it again. Here's an example for you
to experiment with:
WATask subclass: #IsolateExample instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'SCSeasideTutorial' go self inform: 'Before isolate'. self isolate: [self inform: 'Step 1'. self inform: 'Step 2'. self inform: 'Step 3']. self inform: 'After isolate'.Register this as an application and experiment with stepping backward (back button) and forward inside, outside and across the isolate block.
isolate: in
WAStoreTask.