How to auto repeat the on mouseUp [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

morrell
Posts: 84
Joined: Sat Dec 13, 2014 1:12 am

How to auto repeat the on mouseUp [SOLVED]

Post by morrell » Thu Jan 01, 2015 4:48 pm

I'm coming to the end of coding on Android for the project I set myself a month ago (layout will be next) and I'm well and truly stuck on repeating the on mouseUp every X amount of minutes.

As none of the field's information changes except for the system time if the button is manually pressed again and as the user has already answered field EveryXMinutes before the manual click on mouseUp I do get another correct result because the system time has changed.

My problem is how to use this (if correct) put field "EveryXMinutes" * 60 into field "ChangeToSeconds" (I'm presuming seconds has to be used) into getting an auto update every x amount of time until the Cancel button is clicked.

Regards,

Ruth
Last edited by morrell on Fri Jan 02, 2015 3:07 pm, edited 1 time in total.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Thu Jan 01, 2015 5:12 pm

In the on mouseUp handler, take the code and put it into a new, separate handler. Add a "send in time" to call itself again in this handler, as long as the update running flag is set.
In the on mouseUp handler, set a flag to show that the updates are running and put a statement to invoke the new handler.
In the cancel button script, set a flag to show that the updates are not running any more.

So something like:

Card script

Code: Select all

on updateTheData
  if the cUpdatesRunning of this card is true then
    --do whatever your updates need
    --this would be the code you moved from the original mouseUp script
    send updateTheData to this card in (field "EveryXMinutes" * 60) seconds
  end if
end updateTheData
In the Go button script

Code: Select all

on mouseUp
  set the cUpdatesRunning of this card to true
  updateTheData
end mouseUp
In the cancel button script

Code: Select all

on mouseUp
  set the cUpdatesRunning of this card to false
end mouseUp
When the application is closed, you should also perhaps cancel any pending updateTheData messages, just to clean up.

morrell
Posts: 84
Joined: Sat Dec 13, 2014 1:12 am

Re: How to auto repeat the on mouseUp

Post by morrell » Thu Jan 01, 2015 8:38 pm

Thank you SparkOut.

I have done as suggested and whilst I get no errors, there is no auto Go button click after the first manual click.
I append below what I added just in case I'm missing a glaring typo.

Regards,

Ruth

My Card script added to the card containing both the inputs and result:

Code: Select all

on updateTheData
if the cUpdatesRunning of this card is true then
--do whatever your updates need
   --this would be the code you moved from the original mouseUp script
   send updateTheData to this card in (field "EveryXMinutes" * 60) seconds
end if
end updateTheData
My Go button:

Code: Select all

on mouseUp
   set the cUpdatesRunning of this card to true
   updateTheData
end mouseUp
My Cancel button:

Code: Select all

on mouseUp
   set the cUpdatesRunning of this card to false
end mouseUp

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Thu Jan 01, 2015 9:18 pm

Don't think of it as an auto click, your first click sends a message called updateTheData which goes up the message path and is handled by the on updateTheData handler in the card script. Within that handler, if the running flag is true, then it will send another message to be delivered up the message path in the specified time, with no further reference to the original button.
1) The obvious.. your on updateTheData handler does have the code you moved from the original code to update the data as well as what you have added, doesn't it? You need to put it between the if/then parts so that it will only update if the status is running.
2) Check what the EveryXMinutes field contains. Given the calculation, it must contain ONLY a numerica value, not "60 minutes". If you want it to have possible text content you will need to parse out the numeric value to make the calculation of how long in the future to send the next update.
3) Add another button which just

Code: Select all

on mouseUp
  put the pendingMessages
end mouseUp
After you click the go button, click this new one and it should show a list of messages that are pending, it should show one in the list with the name "updateTheData" somewhere in the middle of the line.
If it's not there, then the message isn't being sent. If it is, then we need to check the time involved.

morrell
Posts: 84
Joined: Sat Dec 13, 2014 1:12 am

Re: How to auto repeat the on mouseUp

Post by morrell » Thu Jan 01, 2015 9:39 pm

The EveryXMinutes does only contain a whole numeric value such as 3

The obvious.. your on updateTheData handler does have the code you moved from the original code to update the data as well as what you have added, doesn't it? You need to put it between the if/then parts so that it will only update if the status is running.
Sorry, but I don't understand that part.

I added the button which when clicked says:-
8442,1420144716.367,updateTheData,card id 1283 of stack "C:/01 LIVE CODE/TEST.livecode"
8492,1420144742.946,updateTheData,card id 1283 of stack "C:/01 LIVE CODE/TEST.livecode"
8496,1420144745.916,updateTheData,card id 1283 of stack "C:/01 LIVE CODE/TEST.livecode"
8501,1420144747.362,updateTheData,card id 1283 of stack "C:/01 LIVE CODE/TEST.livecode"
8502,1420144748.878,updateTheData,card id 1283 of stack "C:/01 LIVE CODE/TEST.livecode"

Regards,

Ruth

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Thu Jan 01, 2015 10:38 pm

The code you use to perform the updates is where?
In the original go button you need to cut it out, and just leave it with the setting the update flag and calling the new updateTheData handler.
In the updateTheData handler you need to paste the code from the original button.
Paste it in the place where I put the comment--do whatever your updates need.

morrell
Posts: 84
Joined: Sat Dec 13, 2014 1:12 am

Re: How to auto repeat the on mouseUp

Post by morrell » Thu Jan 01, 2015 11:09 pm

The code you use to perform the updates is where?
If I understand your question correctly I'm not using any update in my code. Previously before adding any of your suggested code, when I clicked the Go button I would have the required answers to my inputs which are based around the system time.
set the twelvehourTime to false
put the long time into field "SThhmmss"

So because the original inputs are still on screen, every time I manually click the Go button after the first time I would have an updated result because there would be a new system time on each subsequent manual click.
So what I'm after is to use the EveryXMinutes field which is not used in my original calculations, so that without clicking the Go button after the first click it will continuously do an auto click Go button using the time delay asked for in the original EveryXMinutes field until the Cancel button is clicked.

So sorry if my original Post question did not make that clear.

Regards,

Ruth

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Thu Jan 01, 2015 11:43 pm

Yes, simply move the code from the on mouseUp handler to that place in the updateTheData handler.

The updateTheData handler should contain the

Code: Select all

set the twelveHourTime to false
Put the long time into field "SThhmmss"
and any other code that you need to deal with every regular interval.

morrell
Posts: 84
Joined: Sat Dec 13, 2014 1:12 am

Re: How to auto repeat the on mouseUp

Post by morrell » Fri Jan 02, 2015 12:12 am

I moved everything from the Go button on mouseUp (not sure what I should leave out) to the --do whatever your updates need and received the error below:

All the result fields are now changing correctly but at less than a second and not on the EveryXMinutes one minute I input and the Message button is not now recording any information.

Regards,

Ruth
Attachments
STerror.jpg

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Fri Jan 02, 2015 12:30 am

OK, we're getting there. We just need to deal with the timing calculation.
First, hard code the send in time statement to

Code: Select all

send updateTheData to this card in 60 seconds
instead of multiplying the EveryXMinutes field. If that works we need to error trap the calculation.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Fri Jan 02, 2015 12:36 am

If that works, then edit the on updateTheData handler with a check for valid integer value in the field

Code: Select all

on updateTheData
   if the cUpdatesRunning of this card is true then
      --do whatever your updates need
      --this would be the code you moved from the original mouseUp script
      set the twelveHourTime to false
      put the long time into field "SThhmmss"
      --any other code you moved here too

      put field "EveryXMinutes" into tMins
      if (tMins is not an integer) or (tMins < 1) then
         put "Invalid interval" into field "EveryXMinutes"
         set the cUpdatesRunning of this card to false
      else
         send updateTheData to this card in (tMins * 60) seconds
      end if
   end if
end updateTheData  

morrell
Posts: 84
Joined: Sat Dec 13, 2014 1:12 am

Re: How to auto repeat the on mouseUp

Post by morrell » Fri Jan 02, 2015 12:46 am

This still results in the same error:-

Code: Select all

updateTheData
      send updateTheData to this card in 60 seconds
      end if
end updateTheData

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Fri Jan 02, 2015 12:48 am

That's not a handler... have you missed copying anything when you pasted it?

morrell
Posts: 84
Joined: Sat Dec 13, 2014 1:12 am

Re: How to auto repeat the on mouseUp

Post by morrell » Fri Jan 02, 2015 1:10 am

This is what I have:

Code: Select all

on updateTheData
   if the cUpdatesRunning of this card is true then
      --do whatever your updates need
      --  below is the System Time to seconds 
      set the twelvehourTime to false
      put the long time into field "SThhmmss"
 Etc Etc Etc

      set the cUpdatesRunning of this card to true
      updateTheData
      send updateTheData to this card in 60 seconds
      end if
end updateTheData
Where should I have placed send updateTheData to this card in 60 seconds

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to auto repeat the on mouseUp

Post by SparkOut » Fri Jan 02, 2015 1:22 am

Aha

Code: Select all

on updateTheData
   if the cUpdatesRunning of this card is true then
      --do whatever your updates need
      --  below is the System Time to seconds 
      set the twelvehourTime to false
      put the long time into field "SThhmmss"
Etc Etc Etc

 -- this is a problem --
      set the cUpdatesRunning of this card to true
      updateTheData 
-- the above two lines should not be here. These are the ones that kick it off in the go button.

      send updateTheData to this card in 60 seconds
      end if
end updateTheData
I will try and upload a small sample stack that you can hopefully see what is going on. It will be zipped, so unzip it first. Then you should be able to open in LiveCode and play with it. I've added a cancellation of the outstanding messages once the cancel button is pressed too.
Attachments
send_sampler.livecode.zip
(1.45 KiB) Downloaded 192 times

Post Reply