Thursday, 10 December 2015

Core 2: Brainstormer Updates

The videos for Core 2: The Brainstormer have been edited to remove 'first takes' as needed. There is no change to the instructional content, so there is no need to revisit videos that students have already viewed. The old versions of the videos are now marked private.

The downloadable AIA file WhoIsQuiz_example.aia has been updated to prevent the app from crashing after the last question is answered. It differs from the code built up in videos 4 and 5 when dealing with user-typed answers, and shown again in video 8 when dealing with the drop-down list, as follows:
  • Incrementing the list index CurrentQuestion has been removed from the SubmitButton event handler in the first version of the quiz, and from the AnswerPicker event handler in the second version.
  • In the NextButton event handler, the test for the end of the list has been changed to a test for equality, as the change above means the list index is not incremented before it is tested.
  • An else clause has been added to the conditional block, in which the list index is incremented and the next image is displayed only if the game is not over.

Before: the index is incremented when the third question is answered correctly, and the NextButton handler then attempts to display the fourth image in a list of three, crashing the app before the check for the end of the game

After: when the Next button is clicked, we check if the game is over; if it's not, the index is incremented and the next image is displayed

It would have been possible to fix the crash without moving the CurrentQuestion increment into the NextButton handler, but the program flow is easier to follow with the solution above. It also means that the AnswerPicker handler (or the SubmitButton handler in the first version) deals only with whether or not the user gave the correct answer, and the NextButton handler deals only with determining how to move the game forward. This is an example of the programming principles of Single Responsibility and Separation of Concerns.

No comments:

Post a Comment