Freezing Repeating Loop Not Tied to Button

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
newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Freezing Repeating Loop Not Tied to Button

Post by newpie » Thu Dec 03, 2015 4:50 am

Hello I wanted to ask if someone could look at this code. I keep getting a frozen stack and unaware of the short keys to kill the stack in this situation -->My second question :)

Goal: To run an "update" handler every 15 min once they enter and have a certain card active.

Issue: What I noticed is it doesn't wait the "10" seconds. The answer box comes back within milliseconds of pressing the OK. Then it freezes livecode.

Code: Select all

On PreOpenCard
   UpdateCheck
end PreOpenCard

on UpdateCheck
repeat
   put the short name of this card into theCard
   if theCard = "TargetCard" then
      updateCARD --handler that does items that is located on stack script as I call it in other handlers as well
      send "UpdateCheck" to me in 10 seconds --this would normally be 600 seconds
      answer "Here"
   end if
end repeat
end UpdateCheck
Any help would be appreciated as this kind of code logic would be useful to me on many levels. Thanks

Third question: Do you recommend me clearing any pending messages as well within this script to prevent memory leaks:

Code: Select all

on MyTimer
   DoSomethingPeriodically
   if MyTimer is not in the pendingMessages then
      send "MyTimer" to me in 1 second
   end if
end MyTimer
http://forums.livecode.com/viewtopic.php?f=9&t=15480

I used this post to help me get started, fyi.
http://forums.livecode.com/viewtopic.php?f=7&t=24243


Thank you for any help in these matters.

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Freezing Repeating Loop Not Tied to Button

Post by quailcreek » Thu Dec 03, 2015 5:55 am

Hi newpie,
You're not telling your repeat when to stop. Repeat for each line theLine in theContainer. Repeat until... Repeat the X = 1 to 20...
Tom
MacBook Pro OS Mojave 10.14

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Freezing Repeating Loop Not Tied to Button

Post by newpie » Thu Dec 03, 2015 6:15 am

Thanks for the quick reply. I actually don't want it to stop, just wait around 10 min between each iteration, unless they exit the program or leave the "target card". Its main purpose is to update a datagrid against an external database.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Freezing Repeating Loop Not Tied to Button

Post by SparkOut » Thu Dec 03, 2015 8:18 am

You don't want the repeats at all. The update check handler calls itself recursively with the "send" timer, and will therefore continue as long as the conditions are met to send the next message. You could make this more general and probably robust by having the condition in the timed loop check for an "IsRunning" flag you set. For example on openCard of "TargetCard" you could set IsRunning to true and send "UpdateCheck" to this card/ stack. On closeCard you can cancel pending messages and set IsRunning to false.

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm
Location: NE USA

Re: Freezing Repeating Loop Not Tied to Button

Post by WaltBrown » Thu Dec 03, 2015 12:57 pm

newpie,
If it's the "answer here" line, it executes immediately after the send command posts the new message, not AFTER the 10 seconds. "Send" does not block.

And like SparkOut says, you don't need the repeat. What's happening is that repeat is just spinning like mad (without a stop, as quailcreek says) posting thousands of new update messages, freezing LC, and then crashing out when you hit some buffer limit. And if the messages even come back, they just start new infinite repeat loops.

Walt
Walt Brown
Omnis traductor traditor

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Freezing Repeating Loop Not Tied to Button

Post by newpie » Fri Dec 04, 2015 12:31 am

Thank you all for helping me understand that concept. I will work on some new coding.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”