What is wrong with this Script logic?

Ben Rubinstein benr_mc at cogapp.com
Fri Jan 11 09:16:07 EST 2013


On 11/01/2013 06:21, Mark Wieder wrote:
> Jacque-
>
> Thursday, January 10, 2013, 9:39:35 PM, you wrote:
>
>> Something's wrong. I think it's the dialog.
>
> My guess is that closeField keeps getting triggered.

It's definitely related to closeField, but there's some interaction with the 
dialog as well.  I tweaked the code as follows:

| on closeField
|    logNote "> closeField"
|    hCheckEntry me
|    logNote "< closeField"
| end closeField
|
| on hCheckEntry pData
|    logNote "> hCheckEntry"
|    repeat until pData is an integer
|       logNote "- hCheckEntry1"
|       ask warning "Please enter only whole numbers!" with pData
|       if the result = "cancel" then exit to top
|       logNote "- hCheckEntry2"
|       put it into pData
|    end repeat
|    --   put pData into me
|    logNote "< hCheckEntry"
| end hCheckEntry
|
| on logNote t
|    global gtTempLog
|    put t & tab & the long time & return after gtTempLog
| end logNote

Putting the whole lot in a button instead of a field, replacing "on 
closefield" with "on mouseUp" - no problem.

However, putting "lock messages" around the "put pData into me" (or even, as 
you see above, just commenting out that part) didn't help.

What the log shows is something like this, if I enter a valid integer into the 
ask dialog the first time it's triggered:
 > closeField 10:45:19 AM
 > hCheckEntry	10:45:19 AM
- hCheckEntry1	10:45:19 AM
- hCheckEntry2	10:45:22 AM
< hCheckEntry	10:45:22 AM
< closeField	10:45:22 AM

(what we'd expect)

Or this if I click Cancel:
 > closeField	10:45:25 AM
 > hCheckEntry	10:45:25 AM
- hCheckEntry1	10:45:25 AM

(again, what we'd expect)

But if the first time round I click OK in the ask dialog with a non-integer 
value, then it "locks up" and I have to interrupt.  When I do, the script 
editor shows me at the top of the repeat loop, and the log shows something 
like this:
 > closeField	10:49:51 AM
 > hCheckEntry	10:49:51 AM
- hCheckEntry1	10:49:51 AM
- hCheckEntry2	10:49:51 AM
- hCheckEntry1	10:49:51 AM
- hCheckEntry2	10:49:51 AM
- hCheckEntry1	10:49:51 AM
.... repeat

In other words the code is cycling through the loop, past the ask statement, 
but no dialog is appearing.





More information about the use-livecode mailing list