calling for opinions
Phil Davis
davis.phil at comcast.net
Fri Feb 10 14:41:36 EST 2006
Hi Ben,
If it works, that's the main thing! For now anyway.
Do you plan to reuse the approach for other quizzes in the future? If
so, you might consider using a design that doesn't require additional
coding (adding and totaling new globals) when the number of questions
changes.
Here's one different approach, and I'm sure there are others that would
also work.
Assumptions:
- all groups in the stack are answer groups
The concepts:
- at openStack time, put all answer groups into the correct state.
- let all answer data be stored as native properties of the objects used
to represent answers. That way you can replicate the group as many times
as you like, edit the radio buttons as needed, and know that each group
will store its own data correctly.
- At "show score" time, process all properties that contain answer data.
The implementation:
- set the NAMES of all radioButtons to the values you want them to add
to the final score: 1, 0, -1. It doesn't matter of you have duplicate
button names in a group.
- set the LABELS of the radioButtons to the answers they represent - the
actual text of the answer.
- put no code in your card or group scripts.
- put this handler in your stack script (watch line wraps):
on openStack -- or preOpenStack if you like
-- put all answer groups into correct initial state
put the number of cds into xMax
repeat with x = 1 to xMax
put the groupIDs of cd x into tList
repeat for each line tGroup in tList
set the hilitedButtonName of grp id tGroup of cd x \
to empty
end repeat
end repeat
end openStack
- put this handler in your "show score" button:
on mouseUp
-- init (not really needed - just my habit)
put zero into tFinalScore
-- collect all answer data
put the number of cds into xMax
repeat with x = 1 to xMax
put the groupIDs of cd x into tList
repeat for each line tGroup in tList
add (the hilitedButtonName of grp id tGroup of cd x) \
to tFinalScore
end repeat
end repeat
-- display score
put tFinalScore into fld "score"
end mouseUp
I didn't test any of this, so there may be a bug or two; but I think it
would give you optimum flexibility in the long term.
HTH -
Phil Davis
Ben Bock wrote:
> I have a quiz that has 6 items per page, with 8 pages. The items are
> grouped radio buttons.
>
> When the "NEXT PAGE" btn is pressed, a card script is triggered:
>
> global b1, b2, b3, b4, b5, b6
>
> --I used globals for holding the value of each item, 1 = correct, -1
> = wrong, 0 = not answered
>
> on closeCard
>
> if the hilitedbutton of group "item1" = 1 then put "1" into b1
>
> if the hilitedbutton of group "item1" = 2 then put "-1" into b1
>
> if the hilitedbutton of group "item1" = 0 then put "0" into b1
>
> --repeated for all items
>
>
>
> at the end there is a field with a "show score" btn:
>
> global b1,b2,b3,b4,b5,b6.....b45
>
> --I have 45 items that each have a global variable
>
> on mouseUp
>
> put the sum (b1,b2,b3,b4,b5,b6...b45) into fld "b score"
>
> end mouseUp
>
>
>
> I've spent a good while getting it ready, and it works. But...are
> there hidden dangers in my chosen approach?
>
> Thanks,
>
> Ben _______________________________________________ use-revolution
> mailing list use-revolution at lists.runrev.com Please visit this url to
> subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list