Execute command every XX seconds [solved!]

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
AlbertoP
Posts: 7
Joined: Thu Nov 13, 2014 2:48 pm

Execute command every XX seconds [solved!]

Post by AlbertoP » Thu Nov 13, 2014 3:17 pm

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!
Last edited by AlbertoP on Thu Nov 13, 2014 4:05 pm, edited 1 time in total.

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

Re: Execute command every XX seconds

Post by magice » Thu Nov 13, 2014 3:37 pm

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

AlbertoP
Posts: 7
Joined: Thu Nov 13, 2014 2:48 pm

Re: Execute command every XX seconds

Post by AlbertoP » Thu Nov 13, 2014 3:57 pm

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!!

AlbertoP
Posts: 7
Joined: Thu Nov 13, 2014 2:48 pm

Re: Execute command every XX seconds [solved!]

Post by AlbertoP » Thu Nov 13, 2014 4:05 pm

It works perfectly, thanks!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Execute command every XX seconds [solved!]

Post by Klaus » Thu Nov 13, 2014 4:06 pm

Hi Alberto,

1. welcome to the forum! :D

2. Here some great learning resources for LC:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

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

Re: Execute command every XX seconds [solved!]

Post by magice » Thu Nov 13, 2014 4:13 pm

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.

AlbertoP
Posts: 7
Joined: Thu Nov 13, 2014 2:48 pm

Re: Execute command every XX seconds [solved!]

Post by AlbertoP » Thu Nov 13, 2014 4:16 pm

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!

Post Reply