In this lecture I will present four different ways of programming essentially the same interaction--a simple True/False exercise--as a means of demonstrating efficient ways of using the structure of LiveCode to create user interactions. At the end of this presentation you will have a chance to try some of these techniques for yourself.
These examples are illustrated in the stack http://dight210.byu.edu/resources/InClass_Work/QuizStacks/InteractionsProgrammingEx.rev.
Method 1 - The way a novice programmer might do it.
Create a third group with the answer buttons in it:
True button, false button (radio style)
This group will have to be duplicated on each new card.
True/False buttons: MouseUp handler which puts appropriate feedback into the feedback field, according to what right answer is.
Card script: openCard handler to empty out the feedback field and reset buttons
Advantages of this approach:
Disadvantages of this approach:
Method 2 - Getting smarter
Merge the true/false buttons into the questionControls group. Delete the extra true/false groups
Card Script: Add to openCard handler, set the custom property of the question group. Be sure to include pass openCard command to ensure the message gets passed to the bgControls group.
QuestionControls group: check the short name of the selected button, compare it to the correctAnswer property
Method 3 - More generalized, more efficient
Use custom property of questionControls group to put all questions and correct answers in a list
Now we can move the openCard handler to questionControls group, because we don't have to hard code the answer on each openCard; check questionlist property on each new card and fill in question fld and correctAnswer property from script
Method 4 - Single card approach
All groups same as above, but only one card is used. Simply replace data on the card for each new question.