Repeat Forever - Not Working

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 137
Joined: Tue Aug 05, 2014 10:07 am

Repeat Forever - Not Working

Post by Googie85 » Tue Jan 19, 2016 3:10 am

I cannot get this following code to work:-

Code: Select all

on mouseUp
     repeat until the mouseClick
            set the visible of image SolidBlue to true
   wait 0.1 seconds
   set the visible of image SolidBlue to false
   set the visible of image SolidRed to true
   wait 0.1 seconds
   set the visible of image SolidRed to false
   set the visible of image HalfBlue to true
   wait 0.1 seconds
   set the visible of image HalfBlue to false
   set the visible of image HalfRed to true
   wait 0.1 seconds
   set the visible of image HalfRed to false
   end repeat
end mouseUp
I have tried everything and it still dosnt want to work.

Many Thanks,

Matthew.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Repeat Forever - Not Working

Post by [-hh] » Tue Jan 19, 2016 5:02 am

Matthew,

when the mouse is up then the mouse has already clicked (the mouseclick is true) and it stops,
"repeat until the mouse is down" would work.

This does the same non-blocking (you could use the half second of each loop for better things than waiting).

Code: Select all

local i0, ii="solidred,solidblue,halfblue,halfred"

on mouseUp
  put "halfred" into i0
  switchit 0
end mouseUp

on switchIt x
  add 1 to x
  if x=5 then put 1 into x
  hide img i0
  if the mouse is down then exit switchit --> see note
  put item x of ii into i0
  show img i0
  send "switchIt x" to me in 100 millisecs
end switchIt
Note. If it should stop after "halfred" only, then use

Code: Select all

if the mouse is down and i0 is "halfred" then exit switchIt
H.
[Edit: Corrected to use different images, saw this too late for my first answer.]
shiftLock happens

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5679
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Repeat Forever - Not Working

Post by jacque » Tue Jan 19, 2016 6:02 pm

Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Repeat Forever - Not Working

Post by [-hh] » Wed Jan 20, 2016 1:29 am

@jacques
Your memo/link is *very* useful for a "dragging-scenario".

But I wonder how you conclude from a loop fired with "mouseUp" and a stop-rule of "clicking" to have a "dragging-scenario"?
shiftLock happens

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5679
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Repeat Forever - Not Working

Post by jacque » Wed Jan 20, 2016 1:49 am

[-hh] wrote:@jacques
Your memo/link is *very* useful for a "dragging-scenario".

But I wonder how you conclude from a loop fired with "mouseUp" and a stop-rule of "clicking" to have a "dragging-scenario"?
The main idea is that scripts should not poll the mouse state unnecessarily. In loops it locks up the CPU, but in this case something else happens. The state of the mouse is only recognized at the exact moment the evaluation occurs. A fast click in a long handler may not occur at that point in the script and the handler won't know the mouse has been clicked.

Your example handlers are almost exactly what should be done, except for adding a flag to track activity. Something like this:

Code: Select all

local i0, ii="solidred,solidblue,halfblue,halfred"
local sFlag

on mouseUp
  put not sFlag into sFlag
  if sFlag then
    put "halfred" into i0
    switchit 0
  end if
end mouseUp

on switchIt x
  if sFlag = false then exit switchIt
  add 1 to x
  if x=5 then put 1 into x
  hide img i0
  put item x of ii into i0
  show img i0
  send "switchIt x" to me in 100 millisecs
end switchIt
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Repeat Forever - Not Working

Post by [-hh] » Wed Jan 20, 2016 8:41 am

@Matthew
As I see know, the question is in "Android Deployment", thus probably touchscreen things come in. I've not enough knowledge of that, so use my answer as a hint only to think about blocking and non-blocking loops. Jacque's answer may also even more applicable from that reason.

@jacque
I'm not convinced by the flag-method to be "the" solution any more. Depends on the situation, platform (incl. HTML5) and hardware (incl. Raspi/slow machines) by the "beat" of the loop. [Especially the usual Mac user behaviour to doubleClick or fast click twice is a hurdle for that, even if one adds other handlers like filtering pendingMessages, indicate the flag's state and so on].
For myself I use also the "poll mouse <in time>"-method because I really can't say one is generally better than the other.
shiftLock happens

Ray@LinkIt.Com
Posts: 6
Joined: Thu Apr 04, 2013 12:19 pm

Re: Repeat Forever - Not Working

Post by Ray@LinkIt.Com » Tue Jan 26, 2016 2:52 am

How about this:

on mouseUp
repeat forever
set the visible of image SolidBlue to true
wait 0.1 seconds
set the visible of image SolidBlue to false
set the visible of image SolidRed to true
wait 0.1 seconds
set the visible of image SolidRed to false
set the visible of image HalfBlue to true
wait 0.1 seconds
set the visible of image HalfBlue to false
set the visible of image HalfRed to true
wait 0.1 seconds
set the visible of image HalfRed to false
if the mouse is down then exit repeat
end repeat
end mouseUp

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Repeat Forever - Not Working

Post by [-hh] » Tue Jan 26, 2016 1:28 pm

This works (as I said above), but *NOT* to do that was exactly our proposal.
Using "send <in time>" takes only the CPU time the animation needs, the rest is taken by the system. Your variant, the "wait", stops for the whole time everything else: No watch is running, no other screen update, everything is blocked by doing "nothing" (while waiting).

For example see the difference by that:
Create a field, set locktext of it to true and set its script to the following (= a "Text-clock"):

Code: Select all

local runShow=false

on mouseUp
   put not runShow into runShow
   showTime
end mouseUp

on showTime
   if runShow then
      put the internet date into me
      send "showTime" to me in (1000 - the millisecs mod 1000) millisecs
   else put "Click me for a digital clock" into me
end showTime
Then watch what this "Text-clock" does ...
(a) ... with your script: it stops until you click again (outside of its rectangle).
(b) ... with one of our scripts above: the clock goes on during the animation.

Our non-blocking scripts are proposals, nothing more.

p.s.Click the field only ONCE each time :-)
shiftLock happens

Ray@LinkIt.Com
Posts: 6
Joined: Thu Apr 04, 2013 12:19 pm

Re: Repeat Forever - Not Working

Post by Ray@LinkIt.Com » Tue Jan 26, 2016 2:46 pm

Whoops - I missed the non-blocking idea in your proposal. Sorry about that. The use of the send command seems the way to go if a non-blocking handler is the goal.

Post Reply

Return to “Android Deployment”