Working with Repeat Loops

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
laurpapo
Posts: 38
Joined: Thu Jun 21, 2012 4:25 pm

Working with Repeat Loops

Post by laurpapo » Sat Jul 07, 2012 7:35 pm

Yet another question that will likely have an obvious answer...

I am trying to present a list of words, one by one, and have the user able to put a definition for each word. When the user clicks next, I want to evaluate whether or not the answer given matches the definition stored in the variable. Whether it is true or not, I want the repeat loop to continue through the list of words. What I have right now is as follows:

put field "Words" of card "Materials" into gMaterials
repeat with x=1 to the number of lines in gMaterials
put item 1 of line x of gMaterials into field "Word"
focus on field "Answer"
wait until gAnswer is not empty with messages
if gAnswer=item 2 of line x of gMaterials then
answer "Well done!"
else if gAnswer<> item 2 of line x of gMaterials then
answer "That is incorrect."
put line x of gMaterials &cr into gTryAgain
end if

end repeat

And the text in the answer field is put into gAnswer when the user clicks a button on the card called 'next'. Right now it keeps stopping at 'wait' point in the script, after I press the 'next' button. It puts the text into gAnswer, but doesn't continue through the rest of the script.

Any help would be much appreciated! Thanks!

-Laurel

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

Re: Working with Repeat Loops

Post by dunbarx » Sat Jul 07, 2012 9:24 pm

Hi,

A couple of observations.

Never name your objects with the likes of "word" or "answer".

Just don't.

I see in your code that the variable "gAnswer" is not ever populated. It will always contain its default contents, which is "gAnswer".

You cannot ever get past that. Was it filled with something from earlier code that was missing from the snippet you gave?

Write back...

Craig Newman

laurpapo
Posts: 38
Joined: Thu Jun 21, 2012 4:25 pm

Re: Working with Repeat Loops

Post by laurpapo » Sat Jul 07, 2012 9:28 pm

I will change gAnswer once I figure out the problem. Thanks for the tip.

I have the text from one of the fields put into gAnswer on mouseup of a button on the card. I thought that could be pressed while I told the script to wait, as long as I had the 'with messages' in there. Does that not work?

Sorry, again, super new at this.

-Laurel

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

Re: Working with Repeat Loops

Post by dunbarx » Sun Jul 08, 2012 2:21 am

If you send a message explicitly with parameters, yes:

Send "yourMessage someParam" to this card. The parameter will be passed with the message, and its value can be read in the target handler.

Otherwise the value must be re-read in some way, either from a global variable, a script local variable or a custom property, as possible vectors.

Craig Newman

laurpapo
Posts: 38
Joined: Thu Jun 21, 2012 4:25 pm

Re: Working with Repeat Loops

Post by laurpapo » Wed Jul 18, 2012 5:02 pm

Thanks for your help!

Post Reply