How do you poll in a program?

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
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

How do you poll in a program?

Post by user#606 » Wed Mar 27, 2013 7:26 pm

The overview of the problem.

I have a series of appointment times that are not visible between those times.
After polling, if the appointment is due, a message is then displayed.

I cannot see how this can be done in an event driven program, when no event triggers the poll.

The usual loop process (as far as I know) will prevent anything else happening, untill the loop ends. In the polling case, it never will. In addition, if the loop was possible, where would the start and end be, so normal button use can continue as the user works with the software?

I could trigger a poll from any buttons in use at the time, but if the user does not press the buttons, then the appointment will not be found and displayed.

So, How can this be done?

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: How do you poll in a program?

Post by magice » Wed Mar 27, 2013 7:49 pm

Look into the "send" command in the dictionary.

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

Re: How do you poll in a program?

Post by FourthWorld » Wed Mar 27, 2013 7:56 pm

user#606 wrote:The overview of the problem.

I have a series of appointment times that are not visible between those times.
After polling, if the appointment is due, a message is then displayed.

I cannot see how this can be done in an event driven program, when no event triggers the poll.
Many event-driven systems include timers, LiveCode among them.

See the "send" command in the Dictionary, noting the "send to <obj> in <time>" option.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: How do you poll in a program?

Post by user#606 » Wed Mar 27, 2013 8:01 pm

Perfect, the send command is just right.
Thank you both.

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: How do you poll in a program?

Post by user#606 » Fri Mar 29, 2013 10:34 am

I have come to use the send command and now realise that the issue of where it is placed in the overall program has not been addressed.

As I clearly stated in my initial question, where does the item that triggers the poll go?

Send has to be in a handler. There is no handler that I can see for it to go in.

Imagine a simple stack with nothing on it at all. The user wants a beep every few seconds.
Using send, one could use

Code: Select all

send "beep" to me in 20 seconds
straight from the dictionary.

There is no handler for it to go into, so how can you use it? There must be a way of triggering an event to poll, independent of any thing else going on, OR NOT, in the program.
I have over simplified I expect, so please read the original post.

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: How do you poll in a program?

Post by user#606 » Fri Mar 29, 2013 12:23 pm

Well, I think I have a solution that appears to work.

Code: Select all

   on opencard
       repeat forever
          wait for 60 second with messages
          beep  -- This is where I would put the poll code
   end repeat  
   end opencard
For those who might be interested.
In my case, there is only one card and I used the

Code: Select all

on opencard
to set the thing off. There is also the same handler in the Stack, but that does not appear to affect anything.
whatever I do on the card, click lines, buttons, fill in fields, load and save data etc, it all works.
The beep goes off after the minute regardless of using the buttons or not. I used a beep so I could tell if anything was happening in the background.

The serious downside is that I have to remember to CtrlC (on PC) to stop the loop so I can edit the code.

Anyway, if anyone has a better idea, please tell me.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How do you poll in a program?

Post by Dixie » Fri Mar 29, 2013 2:04 pm

user606...

I have attached a stack that 'polls'... it is very simple, click the start button and the time will be entered into fld 1 every 5 seconds... click 'stop' and it will... err,,, 'stop'..:-)

besides a handler in each button there is one in the card script...

hope it helps

Dixie
Attachments
polling.livecode.zip
(1.21 KiB) Downloaded 244 times

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: How do you poll in a program?

Post by user#606 » Fri Mar 29, 2013 2:37 pm

Hi Dixie,
That also works!
I will need to think about it to fully understand it.
Thank you very much.

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: How do you poll in a program?

Post by user#606 » Sun Mar 31, 2013 7:18 pm

Hi Dixie,
Using your polling code has been very successfull.
I am not entirely sure how it works, but I will explore it in detail some other time.

A side effect that was unexpected, is that if there is an error in my code that causes the script to stop, it kills the polling.
The only way to get it to go again is to re-start the PC.

A plus is the way that I can change some values in the editing window while the poll is running, so they take effect the moment Apply is clicked.

Anyway, I am a happy LiveCoder.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How do you poll in a program?

Post by jacque » Sun Mar 31, 2013 8:38 pm

You shouldn't have to restart the PC, even if the worst cases you should only need to restart LiveCode. I haven't looked at the example stack, but usually you should just be able to click the start button a couple of times to resend the message. Or type it into the message box.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: How do you poll in a program?

Post by Dixie » Sun Mar 31, 2013 10:32 pm

Jacque...
jacque wrote:...I haven't looked at the example stack...
shame on you !...:-)

Dixie

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How do you poll in a program?

Post by jacque » Sun Mar 31, 2013 11:50 pm

<shamed>
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: How do you poll in a program?

Post by user#606 » Mon Apr 01, 2013 12:37 pm

Hi Dixie and Jacque,
A further observation about the stack, if the poll process stops because of a script error (elsewhere) then the shutting down and restart of Livecode is not enough. The PC must be restarted or the poll will not work. In addition, it leaves a process running with the same name as the stack, when the program/stack is exited, in my case with the red cross top right/Remove from memory is used.
I came across this when I tried to paste an updated version of the program into the "Test folder" that contains the exe
The pre poll version closes and so does the process. This is clearly visible in the Task Manager under processes.

In my case, this is an issue, because it is not convenient in this program to exit by Quit from a button etc.

Any views?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How do you poll in a program?

Post by jacque » Mon Apr 01, 2013 6:02 pm

LiveCode will not fully quit if there are any pending messages in the queue (among other reasons.) If a script error stops the polling, clear out the pending messages before trying to quit the program. You can do that in the pending messages pane of the message box, or you can write a short handler to do it:

Code: Select all

on clearPendingMsgs
 repeat for each line L in the pendingMessages
   cancel (item 1 of L)
 end repeat
end clearPendingMsgs
It should never be necessary to restart your PC. I call a handler ike the one above in a closecard, closestack or shutdown handler in any stack that polls. If you aren't really quitting, you can filter the cancelations by checking to see if L contains your polling command. That will leave any IDE polling messages active.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply