handler troubles

Sarah Reichelt sarah.reichelt at gmail.com
Fri Feb 3 22:40:51 EST 2006


On 2/4/06, Ben Bock <benbock at msn.com> wrote:
> I am going to make a standalone, that saves to a separate data stack.  Right now I have 2 sample stacks to work out the kinks, "button sample" and "data sample".  On the "button sample" stack I have a series of quiz items per card, each with yes or no responses.  I used radio buttons, grouped for each item.
>
> So item #1 has a "YES" btn and a "NO" btn, named "yes1" and "no1", & these are grouped to make "group1".
>
> At the bottom of the page is a btn "Go Next Page", with the script:
>
> on mouseUp
>     put the value of hilitedbutton of group "group1" into field "1" of stack "data sample"
> end mouseUp
>
> This works alright, but it puts "YES" as 1 and "NO" as 2, apparently based on the ID.  What I want
> is to be able to code the correct answers "1" & the incorrect answers as "-1", with the
> unanswered items as "0".

I'm not sure what you will get from "the value" of a button, but here
is one suggestion:

In your "Go Next Page" button:

on mouseUp
  out 0 into tScore

  repeat with g = 1 to the number of groups
    put the hilitedButtonName of group ("group" & g) into tAnswer
    -- the correct answer (Yes or No) is stored in a custom property
of each group
    put the cCorrectAnswer of grp ("group" & g) into tCorrect
    if tAnswer = tCorrect then
        -- right answer
        add 1 to tScore
    else if tAnswer is not empty then
        -- it will be empty if no button has been selected
        subtract 1 from tScore
     end if
  end repeat

  -- process the results
  answer "Your  score in this section was " & tScore

  go next
end mouseUp

This assumes that every group is a set of answers and that the correct
answer for each group is stores as a custom property of that group
called "cCorrectAnswer".

HTH,
Sarah



More information about the use-livecode mailing list