Right answers in Field

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
gcamina
Posts: 10
Joined: Tue Mar 30, 2010 11:36 pm

Right answers in Field

Post by gcamina » Wed Mar 31, 2010 12:11 am

Hi everyone,

I'm new both to Revolution and the forums. I find this program amazingly powerful, but a lot of scripting is necessary for almost every task, and I'm not an expert at it (=hopeless).

I'm trying to develop an application in which my undergraduate students need to press a button in order to hear a word spelt in Spanish (this is easy), and then type it in a text field. How can I script this to show their answers are correct?

I've been using Mediachance's Multimedia Builder so far, and scripting this was quite simple and straightforward, but I have to admit that I'm completely lost as regards revStudio.

Thanks in advance.

MikeinHawaii
Posts: 90
Joined: Mon Jan 18, 2010 10:53 am

Re: Right answers in Field

Post by MikeinHawaii » Wed Mar 31, 2010 6:26 am

All these people here are fantastic, I bet your script shows up real fast. In the meantime I'm new to programming myself, but try looking at three commands in the dictionary- "if" , "then", "else" for starters till they chime in.

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

Re: Right answers in Field

Post by jmburnod » Wed Mar 31, 2010 8:14 am

Hi gcamina,

Welcome
You can use this script to compare two string. It check the accents of each letter

Code: Select all

on VerifAnswer
   put fld "TheQuestion" into text1
   put fld "TheAnswer" into text2
   if CompareText(text1,text2) = empty then
      FaitJuste
   else
      FaitFaux
   end if
end VerifAnswer

on FaitJuste
   Answer "Your answer is true" --or what do you want
end FaitJuste

on FaitJuste
   beep
   Answer "Your answer is false" --or what do you want
end FaitJuste

function CompareText pText1,pText2
   put empty into rCompareText
   put the num of chars of pText1 into nbC1
   put the num of chars of pText2 into nbC2
   if nbC1 <> nbC2 then
      put "PasMemeNombre" into rCompareText
   else
      --•• check the accents of letters by the chartonum function (t)
      repeat with i = 1 to nbc1
         put chartonum(char i of pText1) into CTN1 --•• the num ASCII of letter i of pText1
         put chartonum(char i of pText2) into CTN2 --•• the num ASCII of letter i of pText2
         if CTN1 <> CTN2 then
            put i into rCompareText
         end if
      end repeat
   end if
   return rCompareText
end CompareText
All the best

Jean-Marc
https://alternatic.ch

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Right answers in Field

Post by Klaus » Wed Mar 31, 2010 8:29 am

Hola gcamina,

for the start you could use this simple script.

Script of the button that checks the users input:

Code: Select all

on mouseup
   put fld "user answer" into tAnswer

   ## Presumed you have stored the answer in another field:
   put fld "the correct answer" into tCorrectAnswer

   ## Now a "quick and dirty" comparison :-)
   if tAnswer = tCorrectAnswer then
     ## answer "This is correct."
   else
    ## answer "Nada! Try again!"
   end if
end mouseup
You get the picture :)


Best from germany

Klaus

gcamina
Posts: 10
Joined: Tue Mar 30, 2010 11:36 pm

Re: Right answers in Field

Post by gcamina » Thu Apr 01, 2010 11:08 pm

Wow! Quick answers and both look very interesting!

Jean-Marc, Klaus, thanks for your time. I'm enjoying the not very good weather in County Cork (Ireland) at the moment, but on Monday I'm heading back home and will check your code in my project.

I'll probably have plenty more questions in the near future. I hope I can still count on you. I'm really amazed at how many things you can do with revStudio.

Regards,

Gonzalo

gcamina
Posts: 10
Joined: Tue Mar 30, 2010 11:36 pm

Re: Right answers in Field

Post by gcamina » Thu Apr 01, 2010 11:11 pm

Mikeinhawaii, you're absolutely right.

It's a good idea, but I'd also like to see those commands in context within a few sample projects. Those lists do not say much to absolute beginners.

Regards

Gonzalo

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

Re: Right answers in Field

Post by jmburnod » Fri Apr 02, 2010 6:37 pm

Hi Gonzalo,

First, i'm sorry for my poor english
You can see more exemples on revOnLine

Good luck

Jean-Marc
https://alternatic.ch

gcamina
Posts: 10
Joined: Tue Mar 30, 2010 11:36 pm

Re: Right answers in Field

Post by gcamina » Tue Apr 06, 2010 11:24 pm

Hi, I'm back in cold and rainy Northern Ireland. Nothing like an unwelcoming return home to eagerly try out your solutions for my query. Klaus's works fine, but there must be something wrong with Jean-Marc's (or with me), because it simply doesn't. I've spotted a typo in the code. Where Jean-Marc uses his second "on FaitJuste" I suppose he really means "on FaitFaux". Anyway, it doesn't work even with this thing corrected for some reason that escapes my understanding (very little understanding, that may be the problem).

By the way, Jean-Marc, your written English is good enough and easily understandable (I'd like to say the same thing about some of my native speakers at university), so no worries about that and thank you again for your help.

I think I'm gonna buy the full version of revStudio, because I loooove this program. I hope I can be of some help to others in the future. Until then, I'll need all the examples and advice in this world.

Gonzalo

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Right answers in Field

Post by Mark » Wed Apr 07, 2010 9:35 am

Gonzalo,

Here's Jean-Marc's code again. This version works fine for me (although I don't understand why one would do it this way: it seems a bit complex for this simple task).

Code: Select all

on mouseUp
     VerifAnswer
end mouseUp

on VerifAnswer
   put fld "TheQuestion" into text1
   put fld "TheAnswer" into text2
   if CompareText(text1,text2) = empty then
      FaitJuste
   else
      FaitFaux
   end if
end VerifAnswer

on FaitJuste
   Answer "Your answer is true" --or what do you want
end FaitJuste

on FaitFaux
   beep
   Answer "Your answer is false" --or what do you want
end FaitFaux

function CompareText pText1,pText2
   put empty into rCompareText
   put the num of chars of pText1 into nbC1
   put the num of chars of pText2 into nbC2
   if nbC1 <> nbC2 then
      put "PasMemeNombre" into rCompareText
   else
      --•• check the accents of letters by the chartonum function (t)
      repeat with i = 1 to nbc1
         put chartonum(char i of pText1) into CTN1 --•• the num ASCII of letter i of pText1
         put chartonum(char i of pText2) into CTN2 --•• the num ASCII of letter i of pText2
         if CTN1 <> CTN2 then
            put i into rCompareText
         end if
      end repeat
   end if
   return rCompareText
end CompareText
Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gcamina
Posts: 10
Joined: Tue Mar 30, 2010 11:36 pm

Re: Right answers in Field

Post by gcamina » Fri Apr 09, 2010 4:28 pm

Mark,

Thanks for your revision of Jean-Marc's code. I agree it's somewhat complex, so in the end I applied Klaus's solution and it worked fine, methinks.

For starters I've made up two exercises for my beginners in Spanish, in which (a) they click on buttons and hear the different letters of the alphabet, see how they're pronounced with pop-up labels, and then (b) they listen to 10 words spelt in Spanish (slowly, of course, I'm too nice to them), while they try to put down what they hear, and finally they can check their answers with "?" buttons, where I've used Klaus's wisdom. The result is incredibly good for a total beginner like me.

Pity I have to actually work, because I could spend days "researching" on this program :D . It's highly addictive. I'll be around with more questions, I'm afraid.

Regards

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

Re: Right answers in Field

Post by jmburnod » Fri Apr 09, 2010 7:23 pm

Hi All,

The comparetext function is for letters with accent.
Depend what you want. In revtalk "ñ" = "n" or "é" = "e"

Best

Jean-Marc
https://alternatic.ch

gcamina
Posts: 10
Joined: Tue Mar 30, 2010 11:36 pm

Re: Right answers in Field

Post by gcamina » Sat Apr 10, 2010 2:01 pm

Hi Jean-Marc,

I'll definitely use your CompareText function as well, thanks. As you know, "ñ" and accented letters are something you cannot do without in Spanish.

Regards,

Gonzalo

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Right answers in Field

Post by Mark » Sat Apr 10, 2010 2:15 pm

Hi,

In RunRev 4.0, I enter

Code: Select all

put "eeñ"="een"
and get "false".

Marc's compareText function only returns the number of the last unequal characters. Not only does this function seem unnecessary to me, it also could be written much more efficiently. If you want to know the last characters that are different:

Code: Select all

function compareText theData1,theData2
     repeat with x = max(length(theData1),length(theData2)) down to 1
          if char x of theData1 is not char x of theData2 then return x
     end repeat
     return 0
end compareText
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: Right answers in Field

Post by jmburnod » Sat Apr 10, 2010 3:29 pm

OUPS !

I'm sorry, Mark is right

but
if the casesensitive = false

"f" = "F" return true

Best

Jean-Marc
https://alternatic.ch

Post Reply