What is wrong with this Script logic?

dunbarx at aol.com dunbarx at aol.com
Thu Jan 10 22:54:36 EST 2013


Hi.


Make sure you read the last line...



I can see a recursion issue if the dialog line is skipped, since the handler is called again lower down. Stepping through the script line by line invokes the dialog each time.


As it ought.


But I cannot figure out why this works manually and not when running normally. I have had ghosts all my life in this business, starting in 1987, where stepping through a script goes differently than running that script. Sometimes they fix themselves. Sometimes you just have to rewrite from scratch.


Now here is the rub. Put a manual breakpoint in the calling line in the closeField handler. Pass it by when it comes up. The recursion goes away.


Craig Newman



-----Original Message-----
From: Kay C Lan <lan.kc.macmail at gmail.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Thu, Jan 10, 2013 10:04 pm
Subject: What is wrong with this Script logic?


What is wrong with this Script logic?

I've been staring at this too long and can't figure out what's wrong.

1) New Main Stack
2) Add 1 plain field
3) Set the flds Script to:

on closeField
 hCheckEntry me
end closeField

on hCheckEntry pData
 if (pData is not an integer) then
  ask warning "Please enter only whole numbers!" with pData titled
"Enter A Number"
  put it into tAnswer
  if (tAnswer = empty ) then
   exit to top
  else
   if (tAnswer is not an Integer) then
    --breakpoint --Pos 1
    hCheckEntry tAnswer
    --breakpoint --Pos 2
   else
    put tAnswer into me
   end if
  end if
 end if
end hCheckEntry

If I make the Pos 1 breakpoint active and Pos 2 inactive, then enter A
into the field the ask Dialog comes up with A. If I enter B into the
Dialog then the Dialog reappears with B; this continues for all the
bad data I enter. If I then enter a number or click "Cancel" it all
completes as it should. OK.

If I comment out Pos 1 breakpoint and make Pos 2 breakpoint active,
then when I enter A my ask Dialog comes up with A, BUT if I then enter
B I get an IDE window:

The handler: hCheckEntry has reached the recursion limit of: 400000

If I click the "OK" button on this window to make it go away I am then
presented with my ask Dialog with the B as the default.

If I press "Cancel" my ask Dialog Box comes back with "OK" as the
default answer.

If I press "Cancel" again it finally cancels.

At no time does the debug window come up at my breakpoint.

If I turn Debug Mode OFF, and repeat the above, after I enter B in my
ask Dialog I get the IDE Errors widow come up with:

Type: Handler: can't find handler
Object: fldTest
Line: hCheckEntry tAnswer
Hint: hCheckEntry

My Ask Dialog Box is also presented with B as the default. If I press
"Cancel" my ask Dialog comes back with "ask warning" as the default
answer. If I press 'Cancel' again, it finally cancels.

So why is my script having a recursion problem or not finding the handler?

I'm sure I've written many many similar data checking scripts over the
years and not had this happen.

LC 5.5.3 OS X 10.8.2

_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 




More information about the Use-livecode mailing list