Page 1 of 1
Execute command every XX seconds [solved!]
Posted: Thu Nov 13, 2014 3:17 pm
by AlbertoP
Hi all,
I want to add the option to auto execute a function every 20 or 30 seconds so the user doesn't have to be pushing buttons manually. I read I can use the "send" command, but it doesn't work for me... I wrote something like this:
Code: Select all
on mouseUp
if the hilite of button "AutoRefresh" is true then
repeat forever
send "fillList" to me in 20 seconds
if the hilite of button "AutoRefresh" is false then
exit repeat
end if
end repeat
else
fillList
end if
end mouseUp
But the function fillList doesn't work, it is executed but with errors (doesn't get data from a URL). The function fillList is in the main card of the stack. It works if I call the function (without the send command), it works just fine.
I don't know if I explained myself clearly...
Any ideas?
Thanks!
Re: Execute command every XX seconds
Posted: Thu Nov 13, 2014 3:37 pm
by magice
There is no need for the repeat. just create a command that sends for itself in 20 seconds if the autorefresh button hilite is true.
example (psuedocode)
on fillList
do your current filllist stuff
if the hilite of button autorefresh is true then send fillist to me in 20 seconds
end filllist
Re: Execute command every XX seconds
Posted: Thu Nov 13, 2014 3:57 pm
by AlbertoP
magice wrote:There is no need for the repeat. just create a command that sends for itself in 20 seconds if the autorefresh button hilite is true.
example (psuedocode)
on fillList
do your current filllist stuff
if the hilite of button autorefresh is true then send fillist to me in 20 seconds
end filllist
Nice example, I'll do that, thanks!!
Re: Execute command every XX seconds [solved!]
Posted: Thu Nov 13, 2014 4:05 pm
by AlbertoP
It works perfectly, thanks!
Re: Execute command every XX seconds [solved!]
Posted: Thu Nov 13, 2014 4:06 pm
by Klaus
Hi Alberto,
1. welcome to the forum!
2. Here some great learning resources for LC:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
Re: Execute command every XX seconds [solved!]
Posted: Thu Nov 13, 2014 4:13 pm
by magice
AlbertoP wrote:It works perfectly, thanks!
Now take a few seconds and think about what your original code was doing. It wasn't executing one iteration of the repeat every 20 seconds. instead it was repeating at full speed (which is pretty darn fast) and creating a pending message of "send FillList to me in 20 seconds" So, by the time the first 20 seconds is up, you already have thousands of pending messages. If by then your computer has not yet crashed, you will now start auto-refreshing with the same frequency that the pending messages were created.
Re: Execute command every XX seconds [solved!]
Posted: Thu Nov 13, 2014 4:16 pm
by AlbertoP
magice wrote:AlbertoP wrote:It works perfectly, thanks!
Now take a few seconds and think about what your original code was doing. It wasn't executing one iteration of the repeat every 20 seconds. instead it was repeating at full speed (which is pretty darn fast) and creating a pending message of "send FillList to me in 20 seconds" So, by the time the first 20 seconds is up, you already have thousands of pending messages. If by then your computer has not yet crashed, you will now start auto-refreshing with the same frequency that the pending messages were created.
Yes, now I understand how it works. Thanks!