multiple wait command

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

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

multiple wait command

Post by gilar » Fri Mar 18, 2016 1:59 am

Is there anyway to manage wait command?
I want to affecting "wait command" only for specific task only.
for example: (please look at the code)
wait command "tDelay1" affect "mbtn1" only.
and wait command "tDelay2" shouldn't wait the procces of tDelay1.
I want the both proccess independenly.
Is this make sense?

Code: Select all

      put field delayAP1 into tDelay1
      put field delayAP2 into tDelay2
      put field delayAP3 into tDelay3
      put field delayAP4 into tDelay4
      put field delayAP5 into tDelay5

if the backgroundcolor of btn mAP1 is 128, 0, 0 then
         wait tDelay1 seconds with messages
         send "mouseUp" to button "mbtn1"
      end if
      if the backgroundcolor of btn mAP2 is 128, 0, 0 then
         wait tDelay2 seconds with messages
         send "mouseUp" to button "mbtn2"
      end if
      if the backgroundcolor of btn mAP3 is 128, 0, 0 then
         wait tDelay3 seconds with messages
         send "mouseUp" to button "mbtn3"
      end if
      if the backgroundcolor of btn mAP4 is 128, 0, 0 then
         wait tDelay4 seconds with messages
         send "mouseUp" to button "mbtn4"
      end if
      if the backgroundcolor of btn mAP5 is 128, 0, 0 then
         wait tDelay5 seconds with messages
         send "mouseUp" to button "mbtn5"
      end if
Appreciate for help and comment

Thank You
Gilar | from INDONESIA

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: multiple wait command

Post by dunbarx » Fri Mar 18, 2016 2:42 am

Hi.

You have a series of conditionals, and it seems to me that your handler should work.

BUT, if more than one of those conditionals is true, those will fire as well. Is this what you wanted? Or perhaps only the first one that is true, and all others ignored? Two ways to do that, but first please let me know if that is what you intended.

Why do you need "with messages? Just asking.

Also, just for cleanliness, present your colors as " 128,0,0". You will be glad you did.

Craig Newman

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: multiple wait command

Post by gilar » Fri Mar 18, 2016 5:02 am

dunbarx wrote:Hi.

You have a series of conditionals, and it seems to me that your handler should work.

BUT, if more than one of those conditionals is true, those will fire as well. Is this what you wanted? Or perhaps only the first one that is true, and all others ignored? Two ways to do that, but first please let me know if that is what you intended.


Also, just for cleanliness, present your colors as " 128,0,0". You will be glad you did.

Craig Newman
Hi Craig Thank for Quick respond
What I want is tDelay is independent.
"Wait tDelay2" should not "wait tDelay1", "wait tDelay3", "wait tDelay4", "wait tDelay5"
same as the other, I want The Delay proccess independent.
So I can manage Delay for every button.

My problem Now, I can't execute the 5th button before the 1st button.
They have to wait tDelay1, then tDelay2, then tDelay3, then tDelay4.

Can you image how the logic, I'm having trouble in English, So I couldn't explain it Well I think. Sorry ...
Why do you need "with messages? Just asking.
if without message it will stop my timer.
Gilar | from INDONESIA

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: multiple wait command

Post by dunbarx » Fri Mar 18, 2016 6:00 am

Hmmm.

Try this instead of your "if/then" construction:

Code: Select all

switch
  case the backgroundcolor of btn mAP1 is "128,0,0"
    wait tDelay1 seconds with messages
    send "mouseUp" to button "mbtn1"
    break
  case the backgroundcolor of btn mAP2 is "128,0,0"
    wait tDelay2 seconds with messages
    send "mouseUp" to button "mbtn2"
    break
  case the backgroundcolor of btn mAP3 is "128,0,0"
    wait tDelay3 seconds with messages
    send "mouseUp" to button "mbtn3"
    break
.
.
.
end switch
A "switch" construction will only allow one condition to fire, and the order in which you place the options does not matter. Write back if you have problems.

Craig

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: multiple wait command

Post by gilar » Fri Mar 18, 2016 8:17 am

Thanks Craig ... I'm trying, what you suggest
I'm geting an error, I never use "switch & case"
Please, see my complete code
Is there any wrong code?

Code: Select all

on mouseUp
   if the backgroundcolor of me is empty then
      set the backgroundcolor of me to yellow 
      //DEKLARASI
      put field delayAP1 into tDelay1
      put field delayAP2 into tDelay2
      put field delayAP3 into tDelay3
      put field delayAP4 into tDelay4
      put field delayAP5 into tDelay5
      put field delayAP6 into tDelay6
      put field delayAP7 into tDelay7
      put field delayAP8 into tDelay8
      put field delayAP9 into tDelay9
      put field delayAP10 into tDelay10
      //PUSH
      switch
         case the backgroundcolor of btn mAP1 is 128, 0, 0 then
            wait tDelay1 seconds with messages
            send "mouseUp" to button "mbtn1"
            break
         case the backgroundcolor of btn mAP2 is 128, 0, 0 then
            wait tDelay2 seconds with messages
            send "mouseUp" to button "mbtn2"
            break
         case the backgroundcolor of btn mAP3 is 128, 0, 0 then
            wait tDelay3 seconds with messages
            send "mouseUp" to button "mbtn3"
            break
         case the backgroundcolor of btn mAP4 is 128, 0, 0 then
            wait tDelay4 seconds with messages
            send "mouseUp" to button "mbtn4"
            break
         case the backgroundcolor of btn mAP5 is 128, 0, 0 then
            wait tDelay5 seconds with messages
            send "mouseUp" to button "mbtn5"
            break
         case the backgroundcolor of btn mAP6 is 128, 0, 0 then
            wait tDelay6 seconds with messages
            send "mouseUp" to button "mbtn6"
            break
         case the backgroundcolor of btn mAP7 is 128, 0, 0 then
            wait tDelay7 seconds with messages
            send "mouseUp" to button "mbtn7"
            break
         case the backgroundcolor of btn mAP8 is 128, 0, 0 then
            wait tDelay8 seconds with messages
            send "mouseUp" to button "mbtn8"
            break
         case the backgroundcolor of btn mAP9 is 128, 0, 0 then
            wait tDelay9 seconds with messages
            send "mouseUp" to button "mbtn9"
            break
         case the backgroundcolor of btn mAP10 is 128, 0, 0 then
            wait tDelay10 seconds with messages
            send "mouseUp" to button "mbtn10"
            break
      end switch
      //ELSE==============================================
   else
      //DEKLARASI
      put field delayAR1 into tDelay11
      put field delayAR2 into tDelay12
      put field delayAR3 into tDelay13
      put field delayAR4 into tDelay14
      put field delayAR5 into tDelay15
      put field delayAR6 into tDelay16
      put field delayAR7 into tDelay17
      put field delayAR8 into tDelay18
      put field delayAR9 into tDelay19
      put field delayAR10 into tDelay20
      set the backgroundcolor of me to empty
      //RELEASE
      switch
         case the backgroundcolor of btn mAR1 is 128, 0, 0 then
            wait tDelay11 seconds with messages
            send "mouseUp" to button "mbtn1"
            break
         case the backgroundcolor of btn mAR2 is 128, 0, 0 then
            wait for tDelay12 seconds
            send "mouseUp" to button "mbtn2"
            break
         case the backgroundcolor of btn mAR3 is 128, 0, 0 then
            wait tDelay13 seconds with messages
            send "mouseUp" to button "mbtn3"
            break
         case the backgroundcolor of btn mAR4 is 128, 0, 0 then
            wait tDelay14 seconds with messages
            send "mouseUp" to button "mbtn4"
            break
         case the backgroundcolor of btn mAR5 is 128, 0, 0 then
            wait tDelay15 seconds with messages
            send "mouseUp" to button "mbtn5"
            break
         case the backgroundcolor of btn mAR6 is 128, 0, 0 then
            wait tDelay16 seconds with messages
            send "mouseUp" to button "mbtn6"
            break
         case the backgroundcolor of btn mAR7 is 128, 0, 0 then
            wait tDelay17 seconds with messages
            send "mouseUp" to button "mbtn7"
            break
         case the backgroundcolor of btn mAR8 is 128, 0, 0 then
            wait tDelay18 seconds with messages
            send "mouseUp" to button "mbtn8"
            break
         case the backgroundcolor of btn mAR9 is 128, 0, 0 then
            wait tDelay19 seconds with messages
            send "mouseUp" to button "mbtn9"
            break
         case the backgroundcolor of btn mAR10 is 128, 0, 0 then
            wait tDelay20 seconds with messages
            send "mouseUp" to button "mbtn10"
            break
      end switch
end mouseUp


button "Button": compilation error at line 3 (switch: bad 'case' condition) near "then", char 55
Gilar | from INDONESIA

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: multiple wait command

Post by Thierry » Fri Mar 18, 2016 8:43 am

drop the 'then'

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: multiple wait command

Post by gilar » Fri Mar 18, 2016 8:47 am

Sorry Craig... your code is right.
The script works. I forget to delete "then"

but, This not what I want,

I'm sorry let me explain again

this is my GUI
Image

This is my problem.
I want to execute red button ==> M1, M3, M4, but I wan to have different delay of each.
Now I want to execute M4 button then M3, and M1. I mange this execute with different delay.

if i do setting like this, What happend now is ...
execute wait ..... M1 (for 3 seconds), then M3 (for 5 seconds), M4(for 6 seconds),


Thanks
Gilar | from INDONESIA

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: multiple wait command

Post by dunbarx » Fri Mar 18, 2016 3:20 pm

Gilar.

You have three buttons in red, "M1", M3" and "M4". Each has its own delay setting. Now you want to run all three in sequence, but with the order "M4-M3-M1". If so, then what you want is to check the backColor of each button in turn, from the bottom up, and run the delay for that button if it is red.

I think.

Even if I am still not getting this, please try this experiment.

Make four buttons. Name the first "mbtn1", the next one "mbtn2", and the third "mbtn3". Set the backColor of any two of these buttons to "red". In the script of each button:

Code: Select all

on mouseUp
   put the name of me
end mouseUp
In the last button, place this in its script:

Code: Select all

on mouseUp
   set the delay of btn  "mbtn1" to 3
   set the delay of btn  "mbtn2" to 2
   set the delay of btn  "mbtn3" to 1
   put "waiting"
   repeat with y = 3 down to 1
      if the backColor of button ("mbtn" & y) = "red" then
         wait the delay of btn ("mbtn" & y)  seconds with messages
         send "mouseUp" to button ("mbtn" & y)
      end if
   end repeat
end mouseUp
Click the last button. I am using a custom property ("the delay") to hold the delay time. Trust me, this is easier than loading variables, and trying to associate those values with a list of buttons on the fly.

Craig

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: multiple wait command

Post by gilar » Fri Mar 18, 2016 6:58 pm

Hi Craig ... Thank you very much for keep trying to help me ...
I'm trying to understand your code, Maybe I'll make some experiment with your code.
I'll update here for the result.


Thank You very much.
Gilar | from INDONESIA

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: multiple wait command

Post by dunbarx » Fri Mar 18, 2016 7:57 pm

Gilar.

Keep working. Write back as often as you need to. What I want is to have you enjoy LC, and make beautiful apps.

Craig

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: multiple wait command

Post by Newbie4 » Fri Mar 18, 2016 9:05 pm

I am not sure what you are doing with your code but it sounds like you want independent events each with their own timers. (it is always hard to read someone else's code, especially out of context. Forgive me if I am way off base)

One way of accomplishing that is to have 1 timing loop that executes every sec and over sees all the other "timers".
Each cycle it could decrement each timer, then check if any of them expired or for other events. If a timer expired, then fire it off again, or do something else as a result.

simple code would be:

Code: Select all

on setUp
   put 3 into tDelay1
   put 2 into tDelay2
   put 1 into tDelay3
   checkTimes
end setUp

on checkTimes
   subtract 1 from  tDelay1
   subtract 1 from  tDelay2
   subtract 1 from  tDelay3
   if tDelay1 <= 0 then
      send "mouseUp" to button "mbtn1"
      // or do whatever you need to as a result of the timer on btn 1 expiring
   end  if
   if tDelay2 <= 0  then
      send "mouseUp" to button "mbtn2"
      // or do whatever you need to as a result of the timer on btn 2 expiring
   end  if
   if tDelay3 <= 0  then
      send "mouseUp" to button "mbtn3"
      // or do whatever you need to as a result of the timer on btn 3 expiring
   end  if
   send "checkTimes" to me in 1 sec
end checkTimes
Is this what you were looking to do or did I misunderstand you?
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: multiple wait command

Post by gilar » Sat Mar 19, 2016 3:55 am

Newbie4 wrote:I am not sure what you are doing with your code but it sounds like you want independent events each with their own timers. (it is always hard to read someone else's code, especially out of context. Forgive me if I am way off base)

Is this what you were looking to do or did I misunderstand you?
Hi Newbie4 ... thanks for your code.
Please look at my apps,
Image

M1, M2, M3, etc = selection button, it become red (182, 0, 0) if pressed
mbtn1, mbtn2, mbtn3 = The button I wanto Execute.
ACTION = The button for excecute mbtn1, mbtn2, mbtn3 etc.
In my apps, the variable is very important to me, I mean ... Iwant the Delay variable still exist in GUI.
So I can change the variable on the fly. same as with the selection button (M1, M2, M3, M4 etc.).


for example
I want to execute mbtn4, mbtn7, mbtn8.
So I have to push button M4, M7, M8 (the color of the button must be red)
So when I press ACTION button ... it will execute mbtn4, mbtn7, mbtn8.

There is delay setting in text field. (this is what I said before, I want this variable change on GUI anytime)
If I want mbtn8 the first execution (let say, mbtn8, mbtn7, mbt4), we must fill the delay value with smallest number for the first execute (ex: Delay for mbtn8=3, delay for mbtn7=2, delay for mbtn4=1)
But right now this way never sucsess, because the wait command blocking all all execute command.
The execution still (mbtn4, mbtn7, mbtn8)

I hope my livecode file will give you more explaination
https://drive.google.com/open?id=0BwRId ... kI3WlI5RzQ




Thank You Very Much
Gilar | from INDONESIA

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: multiple wait command

Post by Newbie4 » Sat Mar 19, 2016 6:13 am

I think I understand what you want to do. You want the lights to light at different intervals somewhat based on what buttons the user click. You also want the intervals for each light to be user settable.

The waits are blocking and are linear. They will not work in this case.

What you want to do is let each button be independent with its own time delay and have a timer check them regularly. When that button's interval is over, you send a message for the light to go on/off.

You want a separate loop that checks each button's time interval and adjusts the time (subtract 1 from the interval). When each button's timer gets to zero, then you light that light.

I used a counter (buttonCount) to keep track of the number of lights to go. When they are all lit, then stop the timer (don't send any more startTimer messages)

Using your original code, you would do something like this...

Code: Select all

global buttonCount                           // this keeps track of the buttons being timed. When 0, all are done

on mouseUp                                    // on the Action button
   put field delayAP1 into tDelay1
   put field delayAP2 into tDelay2
   put field delayAP3 into tDelay3
   put field delayAP4 into tDelay4
   put 0 into buttonCount
   if the backgroundcolor of btn mAP1 is 128, 0, 0 then
      add 1 to buttonCount
   end if
   if the backgroundcolor of btn mAP2 is 128, 0, 0 then
      add 1 to buttonCount
   end if
   if the backgroundcolor of btn mAP3 is 128, 0, 0 then
      add 1 to buttonCount
   end if
   if the backgroundcolor of btn mAP4 is 128, 0, 0 then
      add 1 to buttonCount
   end if
   if the backgroundcolor of btn mAP5 is 128, 0, 0 then
      add 1 to buttonCount
   end if
   startTimers
end mouseUp

// each button has it's own time interval.  Every startTimer, we decrement it. As each button hits zero, it lights up. 
// StartTimers checks each button at regular intervals. (I have it at 1 sec but you can make that any time interval.

on startTimers
   if the backgroundcolor of btn mAP1 is 128, 0, 0 then
      subtract 1 from tDelay1                           
      if tDelay1 <= 0 then
         subtract 1 from buttonCount
         send "mouseUp" to button "mbtn1"
      end if
   end if
   if the backgroundcolor of btn mAP2 is 128, 0, 0 then
      subtract 1 from tDelay2                           // 
      if tDelay2 <= 0 then
         subtract 1 from buttonCount
         send "mouseUp" to button "mbtn2"
      end if
   end if
   if the backgroundcolor of btn mAP3 is 128, 0, 0 then
      subtract 1 from tDelay3                           // 
      if tDelay3 <= 0 then
         subtract 3 from buttonCount
         send "mouseUp" to button "mbtn3"
      end if
   end if
   if the backgroundcolor of btn mAP4 is 128, 0, 0 then
      subtract 1 from tDelay4                           // 
      if tDelay4 <= 0 then
         subtract 1 from buttonCount
         send "mouseUp" to button "mbtn4"
      end if
   end if
   if buttonCount > 0  then                            // there are still more buttons to check
      send "startTimers" to me in 1 sec         // so keep timing, else send no more messages
   end if[
   
This should be enough to get you started. There are other minor issues that you need to take care of and there are other ways you can do this.
This way is easier to see what how it works
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: multiple wait command

Post by gilar » Sat Mar 19, 2016 7:09 am

HI Newbie4 .... thank you for keep trying to help me.

I have applied your code on my apps, unfortunately, the delay is not works.
Now I'm trying to understand the workflow of the code, mybe i have to edit on some parts.

Thank you very much
Gilar | from INDONESIA

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

Re: multiple wait command

Post by jacque » Sat Mar 19, 2016 9:08 pm

Newbie is right, you should not use "wait". You can send messages instead that will be executed at the times you specify. Try this:

Code: Select all

on mouseUp -- in the Action button
  -- make a list of all active buttons:
  repeat with x = 1 to 10
    put "M" & x into tBtnName  -- create the button name
    if the backgroundcolor of btn tBtnName = "128,0,0" then
      put tBtnName & comma after tBtnList
    end if
  end repeat
  -- set up pending messages for each button in the list;
  -- these will fire in order by time
  repeat for each item i in tBtnList
    put char 2 to -1 of i into tNum -- extract the number from the button name
    put "mbtn" & tNum into tActionBtn -- create the name of the button to execute
    put fld ("delayAP" & tNum) into tPushDelay -- create the name and get the value of the delay field
    put fld ("delayAR" & tNum) into tReleaseDelay -- create the name and get the value of release field
    send "mouseUp" to tActionBtn in tPushDelay
    send "mouseUp" to tActionBtn in tReleaseDelay
  end repeat
end mouseUp
You should step through each line of the code in the debugger to see what it does. If you don't know how to do that, ask us.

You can track the progress of the list of pending messages in the Pending Messages tab of the Message Box. As the time for each message occurs, a mouseUp will be sent to the correct mbtn. If you have questions about how this works, just ask here.

I did not test the handler so there may be some errors, but it should give you the idea.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply