How do you poll in a program?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How do you poll in a program?
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?
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?
Re: How do you poll in a program?
Look into the "send" command in the dictionary.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How do you poll in a program?
Many event-driven systems include timers, LiveCode among them.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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: How do you poll in a program?
Perfect, the send command is just right.
Thank you both.
Thank you both.
Re: How do you poll in a program?
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 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.
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
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.
Re: How do you poll in a program?
Well, I think I have a solution that appears to work.
For those who might be interested.
In my case, there is only one card and I used the 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.
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
In my case, there is only one card and I used the
Code: Select all
on opencard
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.
Re: How do you poll in a program?
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
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
Re: How do you poll in a program?
Hi Dixie,
That also works!
I will need to think about it to fully understand it.
Thank you very much.
That also works!
I will need to think about it to fully understand it.
Thank you very much.
Re: How do you poll in a program?
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.
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.
Re: How do you poll in a program?
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
HyperActive Software | http://www.hyperactivesw.com
Re: How do you poll in a program?
Jacque...

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

Dixie
Re: How do you poll in a program?
<shamed>
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: How do you poll in a program?
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?
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?
Re: How do you poll in a program?
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:
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.
Code: Select all
on clearPendingMsgs
repeat for each line L in the pendingMessages
cancel (item 1 of L)
end repeat
end clearPendingMsgs
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com