Check the corrects answers

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Check the corrects answers

Post by francof » Sat Jul 26, 2014 11:46 am

ciao all,
here again for a suggestions on how to proceed to check the corrects answers.

my data are into a field divided into 2 colums in which are QUESTIONS and ANSWERS.
answers are only TRUE or FALSE. for e.g.:

black is a color?_ _ _ _ _ true
red is a number?_ _ _ _ _false
ect.

I put the questions item into a group of Text Entry Fields, beside of each field I was thinking to put a group of 2 radio btn. one called btnTrue and the other btnFalse.
now, how can to check if I've clicked the correct btn?
I thought a switch case into the script of the radio btn, using a IF loop. something like:
(for the question:black is a color?,) if myVarAnswer contains "true" the answer is correct else something else.

thanks for your help
franco

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Check the corrects answers

Post by jmburnod » Sat Jul 26, 2014 12:01 pm

Hi Franco,
I see a script that build groups with one fld for the question and one radiobutton for the answer as well you create a link between flds and radiobuttons.
Best regards
Jean-Marc
https://alternatic.ch

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: Check the corrects answers

Post by francof » Sat Jul 26, 2014 2:11 pm

Hi Jean-Marc,

not sure to have understood what you mean. more groups containing 1 field and 1 radio btn? but I think to need 2 radiobtn 1 for each possible answer (true or false)so:
group1 = field1 + radioT1 + radioF1
group2 = field2 + radio2T2 + radioF2
etc.

Best regards
franco

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Check the corrects answers

Post by dunbarx » Sat Jul 26, 2014 2:25 pm

Hi.

If you want to have a single field with many lines, and each line is a question, then you can test in several different ways.

You might place a grouped pair of radio buttons next to each line, and set a property of each pair so it "sees" only the line it is next to, and knows the correct answer. But this requires a lot of setup, and would appear crowded to me. Also, if you wanted to increase or decrease the number of lines, you have to add or subtract radio button pairs. Awful.

Why not make a list field, where the user selects a particular line in that field? That line would hilite, so everyone would know which line was being examined. A single pair of radio buttons can be used for your test. The question is this: let us say the user selects line 3. The correct answer, say, is "false". How would your project know this? The radio buttons have to be aware of the line number, and the correct answer.

Can you do this? Write back if you need more help. This will be a LOT of fun to make.

Craig Newman

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: Check the corrects answers

Post by francof » Sat Jul 26, 2014 5:28 pm

Hi Craig,
dunbarx wrote:Hi.

If you want to have a single field with many lines, and each line is a question, then you can test in several different ways.

You might place a grouped pair of radio buttons next to each line, and set a property of each pair so it "sees" only the line it is next to, and knows the correct answer.
....
this looks nice but complicated for me, I do not have the knowledge to do so.
dunbarx wrote: ....Also, if you wanted to increase or decrease the number of lines, you have to add or subtract radio button pairs. Awful.
...
No, I've a fixed number of questions, ten, at a time.
and, before can see the correct answers, the user must answer at all the questions.

dunbarx wrote:...
Why not make a list field, where the user selects a particular line in that field? That line would hilite, so everyone would know which line was being examined. A single pair of radio buttons can be used for your test....
By what and in my ability so far, a little bit, I thought to fill 10 fields with a repeat loop 1 to 10 with 10 questions from a field containing all questions and answers (named Questionnaire).
beside each field (QuestionX) will be 2 radiobtn 1 for true, 1 for false.

dunbarx wrote: ...
The question is this: let us say the user selects line 3. The correct answer, say, is "false". How would your project know this? The radio buttons have to be aware of the line number, and the correct answer...
into a handler of a button I can check the conditions of all the raidobtn like your example:
I filter the field Questionnaire with the text of the field Question3 and I get the exact answer (item 2) in this case = false. I put it into a variable tTheAnswer.
and now.... I made a test:

Code: Select all

 -- tTheAnswer contains the right answer from the item 2 of field Questionnaire
   if tTheAnswer = 'true' and the hilite of btn 1 of grp "grpDom1" then               --the radio buttons true
      answer "correct"with "Ok"
      exit to top
   else  if tTheAnswer = 'false' and the hilite of btn 2 of grp "grpDom1" then       --the radio buttons false
      answer "correct"with "Ok"
      exit to top
   end if
   answer "wrong"with "Ok"         -- if this line is run means the answer, my friends, is the wrong one
it seems to me that it works, not the best but....What do you say about?
this must be done for all 10 the fields QuestionX, for example I think it could perhaps improve with a loop and indexes to control all the questions, by putting one at a time all the groups of radiobtn into a.... what....
but now I go to cool down my brain......

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Check the corrects answers

Post by jmburnod » Sat Jul 26, 2014 5:37 pm

Hi Franco,
not sure to have understood what you mean. more groups containing 1 field and 1 radio btn? but I think to need 2 radiobtn 1 for each possible answer (true or false)so:
Yes. Sorry for this

Best
Jean-Marc
https://alternatic.ch

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Check the corrects answers

Post by sritcp » Wed Jul 30, 2014 4:22 am

Hi Franco:

You can take advantage of the fact that the "name" of an object and its "label" are two different things.
Here's the trick:
Image
1. Make two radio buttons with labels "True" and False" (This is for Question 1).
Group them into a group named "Question 1"
Now, since you know which answer is correct, give the button with the correct answer the name "Correct"; call the other one "Incorrect".
For example, if "False" is the correct answer, then give the button with the "False" label the name "Correct"; give the button with the "True" label the name "Incorrect"

2. Do this for all your questions.

3. Now group all your groups (Question 1, Question 2, etc..) into a higher level group called "Questionnaire"

4. Now create a button called "Done". This is the button the user will click after answering all your questions.
Put in the script of the button "Done" the following:

Code: Select all

on mouseUp
   local tQuestion
   repeat with i = 1 to the number of groups in group "Questionnaire"
      put the short name of group i of group "Questionnaire" into tQuestion
      if the hilitedButtonName of group tQuestion is "Correct" then answer ("Your answer for" && tQuestion && "is correct!") with "OK"
      if the hilitedButtonName of group tQuestion is "Incorrect" then answer ("Your answer for" && tQuestion && "is incorrect!") with "OK"
      if the hilitedButtonName of group tQuestion is empty then answer ("You did not answer" && tQuestion) with "OK"
   end repeat
end mouseUp
5. You're done! Isn't LiveCode wonderful?

Best wishes,
Sri.

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: Check the corrects answers

Post by francof » Sat Aug 02, 2014 4:24 pm

Hi Sri,

as I said, now I've 1 question at a time and 3 possible answers. so I must use 3 radio btn, one for each answer, and test for the correct one.
I will read well your suggestion to adapt it at the new state.

ciao
franco

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Check the corrects answers

Post by sritcp » Sat Aug 02, 2014 4:54 pm

Hi Franco:

It makes no difference. You will name the button corresponding to the correct answer as "Correct" and the other two buttons as "Incorrect".
(You should, of course, label them to display what you'd like the user to see as possible answers to the question)

Regards,
Sri.

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: Check the corrects answers

Post by francof » Sat Aug 02, 2014 5:26 pm

Hi Sri,
the fact is that now I haven't true or false as possible answer, but 3 different strings. the 3 answers are put in a randomized order, to avoid the correct one is alwais in the same position.
of course I know that the correct one is the ITEM3 of a Table Field.

so, I was thinking to compare this item with the chosen field beside of the radio btn...
I've 2 groups:
grpAnswer = 3 fields
grpRadiobtn = 3 radio buttons

can I give the text of the field as name of a button? there may be a problem of length?

ciao
franco

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Check the corrects answers

Post by sritcp » Sat Aug 02, 2014 8:26 pm

Hi Franco:

Suppose the first question is "What is the capital of Italy?", and the options are Genoa, Rome, Milan.
In my example above, you will have 3 radio buttons (instead of two) in the group "Question 1".
These radio buttons will be labeled, "Genoa", "Rome", and "Milan".
You will also give these three radio buttons the following names: "Incorrect", "Correct", "Incorrect"; Get it?

Do the some thing for each question. You don't have to have 3 options for each question. You can have 2 for some, 4 for others.
Just make sure that the correct radio button is named "Correct" and all others "Incorrect".
You can change the order in which they are displayed, so they cannot guess.

Put all the groups into an overall group called Questionnaire.
Use the code given and you are all set!

[P.S.: Since you know the answer, there is no need to put it in a field.
(Of course, you'll need a field to place your question) ]

Regards,
Sri.

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: Check the corrects answers

Post by francof » Sun Aug 03, 2014 9:12 am

good Morning Sri,

something still escapes me.
sritcp wrote:...
Just make sure that the correct radio button is named "Correct" and all others "Incorrect".
You can change the order in which they are displayed, so they cannot guess.
...
the point is that when I put the 3 answers in 3 fields to display them I don't know where is the correct one, because I first mixed them.
you say always put fields and buttons in different position on the card, instead of randomize the lines of the field answers (fldRisposte)?

I don't know, below what I've:
the 3 answers before mixing, the first is always the correct
1.jpg
1.jpg (11.83 KiB) Viewed 9030 times
after the mixing, in this case the correct one is gone in the third line
2.jpg
2.jpg (12.34 KiB) Viewed 9030 times
fldRisposte is an hidden field

and here displayed in the card
3.jpg
3.jpg (35.81 KiB) Viewed 9030 times
ciao
franco

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Check the corrects answers

Post by sritcp » Sun Aug 03, 2014 1:40 pm

Hi Franco:

You don't have to use a field to store the answers; you can directly label the radio buttons and then randomize.
BUT, if you prefer to have a hidden field to store your answers, here's what you can do:

1. Add an item to the field indicating if the answer is correct. Your example field will then look like this:
Sulla PUNTA, Correct
Nella zona CENTRALE, Incorrect
Nella zona LATERALE ESTERNA, Incorrect

2. After randomizing the field (as you do now), simply set the label and name of the radio button to the items in the field:

Code: Select all

repeat with i = 1 to 3
set the label of button i of group "Question 1" to item 1 of line i of field "Field1"
set the name of button i of group "Question 1" to item 2 of line i of field "Field1"
end repeat
The rest of the procedure stays the same as before.

Regards,
Sri

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: Check the corrects answers

Post by francof » Sun Aug 03, 2014 4:31 pm

Hi Sri
sritcp wrote:...
1. Add an item to the field indicating if the answer is correct. Your example field will then look like this:
...
2. After randomizing the field (as you do now), simply set the label and name of the radio button to the items in the field:
here is what I was missing! finally we got the solution

I've adapted your code,

Code: Select all

put item 3 of line tCont of fld "fldDomandeScelte"& tab & esatta & return after field "fldRisposte"    
      put item 4 of line tCont of fld "fldDomandeScelte"& tab & errata & return after field "fldRisposte"    
      put item 5 of line tCont of fld "fldDomandeScelte"& tab & errata & return after field "fldRisposte"    
  ...
--I only set the name of the btn, the correct answer is show in a field
      repeat with i = 1 to 3
         set the name of button i of group "grpRM" to item 2 of line i of field "fldRisposte"
      end repeat
and here in the script of group buttons

Code: Select all

if the hilitedButtonName of group grpRM is "esatta" then  --correct se si risponde corettamente il nome del tasto sarà "esatta" 
      set the visible of fld "lblRispEsatta" to true
   else
       set the visible of fld "lblRispErrata" to true                       -- wrong altrimenti si sarà data la risposta "errata"
   end if
thanks for your help
ciao
franco

Post Reply