Radio Button Help!

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
stuartls
Posts: 49
Joined: Mon Jan 22, 2007 10:59 pm
Contact:

Radio Button Help!

Post by stuartls » Tue Jan 23, 2007 9:30 pm

I am new to revolution, but willing to learn and I am making progress. I am developing test review software. Each test will have 200 questions. I don't have a problem getting the questions on the card and have buttons at the bottom to go to the next question, or previous question and so forth. My problem is each question has 4 answers. Only one of them is right of course. How do I record which radio button the student selected so I can test later on, at the end of the test if the student got that particular question on the card wrong? I need to set it up in such a way that if they choose one answer and select that radio button, then go back and change their answer then the container reflects the changed answer. The radio buttons are mutually exclusive of course. I've done that! Having a real problem with this. Any help or direction would be greatly appreciated.

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Radio Button Help!

Post by marielle » Tue Jan 23, 2007 9:45 pm

stuartls wrote:I need to set it up in such a way that if they choose one answer and select that radio button, then go back and change their answer then the container reflects the changed answer. The radio buttons are mutually exclusive of course. I've done that! Having a real problem with this. Any help or direction would be greatly appreciated.
This behavior is given if you group all four radio buttons within a group. Then only one can be active at a time.

To get the active one in the group, type something like this:

Code: Select all

put the long id of group "answersOfQuestion24" into tGpRef
put -1 into tResult
repeat for x = 1 to the number of buttons in tGpRef
  put the long id of button x of tGpRef into tBtnRef
  if the hilited of tBtnRef is true then 
    put x into tResult 
    -- put the short name of tBtnRef into tResult
    -- put the label of tBtnRef into tResult
    exit repeat
  end if
end repeat
-- do something with tResult
(written on the fly and untested, feel free to correct me)

stuartls
Posts: 49
Joined: Mon Jan 22, 2007 10:59 pm
Contact:

Post by stuartls » Tue Jan 23, 2007 10:02 pm

Thanks Marielle!

I frankly don't quite know what your wrote, BUT it gives me something to disect and figure out how it works. I'm a newbie, but again, want to learn. I appreciate your help very much!

Stu

stuartls
Posts: 49
Joined: Mon Jan 22, 2007 10:59 pm
Contact:

Can I not do this?

Post by stuartls » Tue Jan 23, 2007 10:21 pm

On my final card can I not have a button that says "Grade Exam" and will go to each card and retrieve the hilited button and check it in with an if statement. Thinking the get statement would do it.

Stu, hope this makes sense....

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Can I not do this?

Post by marielle » Wed Jan 24, 2007 1:45 am

stuartls wrote:On my final card can I not have a button that says "Grade Exam" and will go to each card and retrieve the hilited button and check it in with an if statement. Thinking the get statement would do it.
A bit more of new vocabulary for you.

Easy approach: Have in you radio button name some prefix or suffix that unambiguously separate out the correct answer to the question
button 1 -> option1
button 2 -> option2
button 3 -> correct
button 4 -> option4

This way, you can use the repeat above and add as a condition:

Code: Select all

if the short name of button x of group "answerToQuestion24" is "correct" then
  if the hilited of button x of group "answerToQuestion24" is true then
    -- correct and selected as correct
    add 1 to score 
  else
    -- correct but not selected as correct
    add -0.5 to score
  end  if
end if
For when you start to be comfortable with the basics, a better way to do is by using custom properties. Use the property palette of any object to set the custom property to a given value. You can also do it via the messagebox: set the isCorrect of the selectedobject to true
then you can replace the above with

Code: Select all

if the isCorrect of button x of group "answerToQuestion24" is true then
 ...
end if
Looping through the card, that's the same logic as looping through the button. I leave it to you as an exercise. If you have only one group on each card, you can simply refer to 'group 1 of card tCardNb'. If you have more than one group on each card, then you may want to always name the group that contains the radio buttons the same way 'group "answsers" of card tCardNb'

stuartls
Posts: 49
Joined: Mon Jan 22, 2007 10:59 pm
Contact:

Post by stuartls » Wed Jan 24, 2007 3:25 am

Let me see if I can put this in my terms. I have so far 5 cards. So basically 5 questions. Each question has 4 answers. On the final card I have a button that says "grade exam". Under it,s script is the on mouse up and on mouse down ending. I can go to each card and name each individual button and can name the group that contains the radio buttons. In my terms I want to write in the script. "go back to card # 1027 and find out which button is highlighted and if it is the right one add 1 to the score if not substract one from the score. I have no idea what you mean by short name. I also don't know what you mean by "x". Here is the script that i have typed into the button that says "grade exam".
on mouseUp
put the hilitedButtonID of group 1012 of cardIDs 1002 into tGpRef
if tGpref=1005 add 1 to field "right"
else add 1 to field "wrong"
end mouseUp

It doesn't work. I have named the fields as a type of counter that is visible. Don't know why.

Klaus
Posts: 12216
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Wed Jan 24, 2007 1:39 pm

Hi stuartls,

1. you can check the currently hilited radiobutton in a group much more effective with:

...
the hilitedbutton of grp "radio group"
## Will return the NUMBER of that button IN that group
## NOT the number of the button on the card!
## or use
the hilitedbuttonname of grp "radio group"
## will return the NAME of the button
...

Really NO need to loop through all the buttons ;-)

2. What exactly do yopu mean "It doesn't work" with "hilitedbuttonid"?
Does work here for me!?


Regards

Klaus

Klaus
Posts: 12216
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Wed Jan 24, 2007 1:41 pm

Ah, maybe this is the problem? You forgot THEN!

You wrote: if tGpref=1005 add 1 to field "right"

Correct: if tGpref=1005 THEN add 1 to field "right"

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Wed Jan 24, 2007 6:31 pm

Klaus wrote:the hilitedbutton of grp "radio group"
Thanks for the tip, Klaus. I thought a shortcut must exist but I never found out about it. Sometimes 4 lines of code are quicker than opening the doc ;-)

Marielle

Klaus
Posts: 12216
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Wed Jan 24, 2007 7:09 pm

Well, 8 lines actually ;-)

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Wed Jan 24, 2007 8:50 pm

Klaus wrote:Well, 8 lines actually ;-)
You have a point :oops:

xApple
Posts: 113
Joined: Wed Nov 29, 2006 10:21 pm
Location: Geneva

Post by xApple » Thu Jan 25, 2007 8:21 pm

It's a very bad way to go, to make 200 cards, on for each question...

Suppose you want to change the positions of the radio buttons or the appearance of the interface... you are not going to change each card individually...

Your best solution is to have only 1 card containing 4 radio buttons...
And change their names as the student advances in the exam...

You can store your questions and answers in a field on a second card... the "dataCard" for instance...

To learn the general scripting language, the documentation is your best friend... when you are puzzled by terms like "the short name", just type "name" in the dictionary, and you'll understand everything... check out the pre-made scripts too, called "recipes"; they can give you a feel for string manipulation and repeat loop structure.

Cheers.

stuartls
Posts: 49
Joined: Mon Jan 22, 2007 10:59 pm
Contact:

Post by stuartls » Thu Jan 25, 2007 9:01 pm

Well it going to be 200 cards for each practice test. I do agree that there should, and probably is an easier way to go. That is why I'm only going to do a practice test with only 5 questions. I want the program to fully work before I add the other 195 questions and answers. I'm hoping that as I just put together the smaller test that different ways will emerge to do it more efficently and easier. I do agree with your suggestion of the online documentation. It does help me. I'm just learning as you well know and picking up pieces of advice from people such as yourself helps people like me greatly. I DO strongly believe at THIS time that the "Software at the speed of thought" book by Dan Shafer was a waste of my money. I find it to not be a good book to teach the software and certainly not for reference. I frankly find it poorly written. BUT I certainly want to thank you for any quidance you can give me!

Thanks again X
Stu

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”