pause repeat loops, resume; run on set time

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
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

pause repeat loops, resume; run on set time

Post by keram » Tue Nov 19, 2013 12:25 pm

Hello,

Now I got stuck with my stack. :( I've been trying to get it working for the past 2-3 days.
Looked through the LC manual and the Dictionary but could not find any solution.

Here are the points I'm trying to get working:

1. To be able to pause the 1 st repeat loop on the Settings card, and resume from the same line it stopped on or if this repeat is paused and I would manually look at few next lines then it should resume from the last line that was viewed.

2. To set a particular time of the day to start the repeat loop (2nd option on the Settings card). If this repeat is paused and I would manually look at few next lines then it should resume from the last line that was viewed.

The code on the stack is:

Code: Select all

global gtext2display,frequency,thisLine,currentLine,showAtTime

on openStack
   --   ## Display correct line number, mandatory for your calculation
   --   ## in the navigation buttons/images
   put 1 into fld "showingLine"
   put line 1 of gtext2display into fld "text2display"
   
   if the hilite of btn "set_frequency" of cd "settings" then
      put 0 into fld "showingLine"
      repeat for each line thisLine in gtext2display
         put thisLine into fld "text2display"
         add 1 to fld "showingLine" -- increment counter
         ## ticks will be substituted for seconds once the testing is done
         wait for frequency ticks
         --      wait for frequency seconds
         wait 0 milliseconds with messages
      end repeat
   end if
   
   
   ## how to make NEXT and PREVIOUS, FIRST and LAST line buttons function
   ## when the reapeat is running or when it's paused?
   ## (how to pause the repeat with the PAUSE button?)
   
   
   ## how to set the repeat to start at the showAtTime ?
   ## what's the fault in the script below? (it does not work).
      if showAtTime > 0 then
      set the twelveHourTime to false
      repeat for each line thisLine in gtext2display while showAtTime = the time
         wait 65 seconds
         add 1 to fld "showingLine" -- increment counter
      end repeat
   end if
   
end openStack
The code on the Settings card is:

Code: Select all

global gtext2display,frequency,thisLine,currentLine,showAtTime

on closeCard
   if the hilite of btn "set_frequency" of cd "settings" then
      put (label of btn "everyhour" * 360 + label of btn "everyminutes" *60) into frequency
   else 
      put 0 into frequency
   end if
   
   if the hilite of btn "set_time" of cd "settings" then
      set the twelveHourTime to false
      put label of btn "time_hour" of cd "settings" & ":" & label of btn "time_minutes" of cd "settings" into showAtTime
   else 
      put 0 into showAtTime
   end if
   
   put empty into gtext2display
   if the hilite of btn "a" of cd "settings" then
      put fld "Field 1" of cd "files" after gtext2display 
   end if
   if the hilite of btn "b" of cd "settings" then
      put fld "Field 2" of cd "files" after gtext2display
   end if
   if the hilite of btn "c" of cd "settings" then
      put fld "Field 3" of cd "files" after gtext2display
   end if
   put the number of lines of gtext2display into fld "numberOfLines" of cd "home"
end closeCard

## How to pause and resume the repeat from the line it was paused on??
## how to resume from currentLine after pausing or closing the stack??
I'm attaching the stack.
Appreciate any help with this.

keram
Attachments
next-previous-repeat-stop.zip
(17.12 KiB) Downloaded 243 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: pause repeat loops, resume; run on set time

Post by [-hh] » Tue Nov 19, 2013 2:44 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:13 pm, edited 1 time in total.
shiftLock happens

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: pause repeat loops, resume; run on set time

Post by keram » Tue Nov 19, 2013 5:43 pm

Hi hh,

Thanks for your reply.
[-hh] wrote:your script
repeat for each line thisLine in gtext2display while showAtTime = the time
is not working because you use two methods. You can use
EITHER
repeat for each line thisLine in gtext2display

end repeat
OR
repeat while showAtTime = the time

end repeat
or one method after the other but not both together in one line.
But, didn't I put these 2 methods one after the other in the code?

Does it mean that I cannot set it to show a new line let's say at 13:30 o'clock and at the same time set it to show new line every 3 hours?

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: pause repeat loops, resume; run on set time

Post by [-hh] » Tue Nov 19, 2013 6:23 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 11:45 am, edited 1 time in total.
shiftLock happens

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: pause repeat loops, resume; run on set time

Post by keram » Wed Nov 20, 2013 3:46 am

Hello[-hh],
[-hh] wrote:Do repeat not for each line but with an index counter
Just so that I understand it better - is this for the purpose of adding some code and being able to resume from paused line?

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: pause repeat loops, resume; run on set time

Post by Simon » Wed Nov 20, 2013 4:48 am

Hi keram,
I'm just jumping in here but not to answer your question but to ask you one.

Is this app for iPhone?
Looking at the physical size of your stack I'm thinking it may be.

Now again, I'm not sure, but in the "set the time" I think you want the app to "wake up" at a particular time? Like an alarm clock?
This cannot currently be done in liveCode, once the app is in the background it can be removed from memory at any time (when the device needs to use the space).
mobileCreateLocalNotification can be used but it's not your app running.

Now if this is a desktop app or it's not like an alarm clock function then forget everything I just said. :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: pause repeat loops, resume; run on set time

Post by keram » Wed Nov 20, 2013 5:39 am

Thanks Simon,
Simon wrote:Is this app for iPhone?
Looking at the physical size of your stack I'm thinking it may be.
I though for both IPhone and Android, and Windows as well.
The size I would change later - I set it for small size just during developing it.
Simon wrote: I'm not sure, but in the "set the time" I think you want the app to "wake up" at a particular time? Like an alarm clock?
I thought that the app would be running all the time since the other setting - Chose frequency - would possibly also be selected.
Simon wrote:This cannot currently be done in liveCode, once the app is in the background it can be removed from memory at any time (when the device needs to use the space).
It's good to know!
I don't have any smartphone yet, so I assume, running in the background means that some other app is visible on the screen, right?
Simon wrote:mobileCreateLocalNotification can be used but it's not your app running.
Can it be used to show next text line according to the settings in the app?
If not, is there there any other option to have the app running in the background and yet show next text line? Perhaps by creating a Widget?

It's very useful to get the feedback from you.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: pause repeat loops, resume; run on set time

Post by Simon » Wed Nov 20, 2013 6:09 am

Hi keram,
running in the background means that some other app is visible on the screen, right?
Yes, this also happens when the phone sleeps.
I thought that the app would be running all the time
I think setting the mobileLockIdleTimer you might be able to keep the app running all the time but, in general it's bad practice because it will drain the battery fast. Oh and then there is the power switch which will sleep the device.
Can it be used to show next text line according to the settings in the app?
Yes! But remember it's not actually your app running but a system message in the OS. You tell the OS to put an alert up at a certain time. I still am unclear what your app does (I guess plays a movie or audio, didn't look that deeply into your code) but you can take the list and post multiple messages (say at 13:30 each day), not sure how far into the future you can go.

All the above is only about mobile devices.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: pause repeat loops, resume; run on set time

Post by keram » Wed Nov 20, 2013 9:50 am

Hi Simon,
Simon wrote: I still am unclear what your app does
Just displaying a line of text, it could be a quote or reminder.

But let's take an example from the apps that display the quotations (in case you have one). Are they running all the time? (Sorry to bother you with this question, but I cannot check it myself right now).

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: pause repeat loops, resume; run on set time

Post by FourthWorld » Wed Nov 20, 2013 4:43 pm

Rather than envision the goal as a repeat loop, it may be helpful to think of it as a repeated action.

With that perspective timers become evident as a solution, by putting the action in a handler that calls itself periodically:

Code: Select all

on MyPeriodicTask
   DoSomething -- of course replace this with the action you want to happen
   if "MyPeriodicTask" is not in the pendingMessages then -- avoiding cases where they may accumulate
      send "MyPeriodicTask" to me in 10 seconds -- or whatever interval you like
   end if
end MyPeriodicTask
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: pause repeat loops, resume; run on set time

Post by Simon » Wed Nov 20, 2013 9:13 pm

Hi keram,
You can test it in the sim.
No sound though.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: pause repeat loops, resume; run on set time

Post by keram » Thu Nov 21, 2013 2:18 pm

Hi Richard,
FourthWorld wrote:Rather than envision the goal as a repeat loop, it may be helpful to think of it as a repeated action.

With that perspective timers become evident as a solution, by putting the action in a handler that calls itself periodically:
Thanks for suggestion... It does not tell me much right now - I'm still a complete beginner. I will have to chew a lot on your seed idea, search for meaning of these lines of code that you provided and try to digest it.

Regards,

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply