Doing something at time intervals
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Doing something at time intervals
Hi all,
I think I need a repeat loop to do this. But for different time intervals (e.g., every 0.2 seconds of 2.4 seconds) I want to do an action. How would this look?
Long story short, I want a bar to grow or shrink as time passes. Any help would be appreciated.
Josh
I think I need a repeat loop to do this. But for different time intervals (e.g., every 0.2 seconds of 2.4 seconds) I want to do an action. How would this look?
Long story short, I want a bar to grow or shrink as time passes. Any help would be appreciated.
Josh
Re: Doing something at time intervals
Hi josh,
Here is a little stack which does a part of job.
I remains a little confused about results we get in fld "fdev"
I hope this help and anyway i'm sure someone will help us
As some people said "together we are smarter"
Best regards
Jean-Marc
Here is a little stack which does a part of job.
I remains a little confused about results we get in fld "fdev"
I hope this help and anyway i'm sure someone will help us

As some people said "together we are smarter"
Best regards
Jean-Marc
- Attachments
-
- stProgressBarWithInTime.zip
- (1.8 KiB) Downloaded 209 times
Last edited by jmburnod on Thu Aug 17, 2017 4:22 pm, edited 1 time in total.
https://alternatic.ch
Re: Doing something at time intervals
Hi.
I am still in v6, so I could not open Jean-Marc's stack. But I played around just a bit and offer a little gadget. Make two buttons, name one of them "x". In the script of the other button;
I wonder what Jean-Marc's approach was. I must upgrade.
Craig Newman
I am still in v6, so I could not open Jean-Marc's stack. But I played around just a bit and offer a little gadget. Make two buttons, name one of them "x". In the script of the other button;
Code: Select all
on mouseUp
set the width of btn "x" to 125
shrinkGrow 1
end mouseUp
on shrinkGrow tChange
if the optionKey is down then exit to top
put 1 into waitTime --this is your interval in ticks
put the loc of btn "x" into tLoc
set the width of btn "x" to the width of btn "x" + tChange
if the width of btn "x" >= 150 then put "-1" into tChange
if the width of btn "x" <= 100 then put "1" into tChange
set the loc of btn "x" to tLoc
send "shrinkGrow" && tChange to me in waitTime
end shrinkGrow
Craig Newman
Re: Doing something at time intervals
SorryI could not open Jean-Marc's stack
I save stack to legacy for LC 5 and replaced in my first post
Jean-Marc
https://alternatic.ch
Re: Doing something at time intervals
Jean-Marc.
I was embarrassed because I am stuck in an old version of LC. Your stack was done in v.8x, no?
Craig
I was embarrassed because I am stuck in an old version of LC. Your stack was done in v.8x, no?
Craig
Re: Doing something at time intervals
Craig,
Here is the recipe
One progressbar »mYProgressBar »
One btn « startMyLoop »
One btn « stopMyloop »
One fld « fDev" to spy process
btns script:
cd script:
Yes, I thought that a saved file to legacy LC 5.x works for LC 6.xYour stack was done in v.8x, no?
Here is the recipe
One progressbar »mYProgressBar »
One btn « startMyLoop »
One btn « stopMyloop »
One fld « fDev" to spy process
btns script:
Code: Select all
on mouseUp
do (the short name of the target)
end mouseUp
Code: Select all
local sTimeStart,sTimeSend,sCount
on startMyLoop
if "doMyLoop" is not in the pendingmessages then
put empty into fld "fDev"
put 0 into sCount
doResetMyPB 0,2400,0
put 200 into sTimeSend
put the milliseconds into sTimeStart
doMyLoop
end if
end startMyLoop
on stopMyloop
doStopPending "doMyLoop"
end stopMyloop
on doStopPending pMessage
repeat for each line aLine in the pendingmessages
if pMessage is in aLine then
cancel item 1 of aLine
end if
end repeat
end doStopPending
on doResetMyPB pStart,pEnd,pTB
set the startValue of sb "myProgressBar" to pStart
set the endValue of sb "myProgressBar" to pEnd
set the thumbpos of sb "myProgressBar" to pTB
end doResetMyPB
on doMyLoop
add 200 to sCount
if sCount > 2400 then
doStopPending "doMyLoop"
exit doMyLoop
end if
set the thumbpos of sb "myProgressBar" to sCount
put the milliseconds into tTimeLoop
put getSomething() into tDoSomeThing
get sTimeSend - (the milliseconds - tTimeLoop)
put max(1,it) into tDelai
put the milliseconds - sTimeStart && tDelai & cr before fld "fDev"
send doMyLoop to me in tDelai milliseconds
end doMyLoop
function getSomething
put empty into rgetSomething
repeat with i = 1 to 2
put random(100) & cr after rgetSomething
end repeat
delete char -1 of rgetSomething
return rgetSomething
end getSomething
https://alternatic.ch
Re: Doing something at time intervals
Thank you all!
I spent all day yesterday trying different approaches. I'll never be as good as all of you, but I do love programming. I did give both approaches here (and a few I found via google) a go. In the end, I went with the below. I know I've mangled your eloquent code, but I definitely appreciate the help.
Love this community.
Josh
global stopMe
on mouseUp
put true into stopMe
end mouseup
global counter, tCurrentProgress
on mouseUp
set backgroundcolor of graphic "tRect" to white
set backgroundcolor of graphic "tFill" to black
set the Width of graphic "tFill" to zero
set the left of graphic "tFill" to the left of graphic "tRect"
put 0 into counter
put 0 into tCurrentProgress
end mouseUp
global counter, tCurrentProgress, unit, stopMe
on mouseUp
put width of graphic "tRect" div 30 into unit
put false into stopMe
shrinkGrow 1
end mouseUp
on shrinkGrow tChange
if ((the altkey is down) or (stopMe is true)) then exit to top
put 1 into waitTime
if the width of graphic "tFill" < the width of graphic "tRect" then
set the width of graphic "tFill" to the width of graphic "tFill" + unit
set the left of graphic "tFill" to left of graphic "tRect"
--set the right of graphic "tFill" to right of graphic "tRect"
end if
if the width of graphic "tFill" >= the width of graphic "tRect" then
set the width of graphic "tFill" to 0
set the left of graphic "tFill" to left of graphic "tRect"
set the right of graphic "tFill" to right of graphic "tRect"
if the backgroundcolor of graphic "tFill" is yellow then set backgroundcolor of graphic "tFill" to black
if the backgroundcolor of graphic "tFill" is blue then set backgroundcolor of graphic "tFill" to yellow
if the backgroundcolor of graphic "tFill" is green then set backgroundcolor of graphic "tFill" to blue
if the backgroundcolor of graphic "tFill" is black then set backgroundcolor of graphic "tFill" to green
//do nothing
end if
send "shrinkGrow" && tChange to me in waitTime seconds
end shrinkGrow
I spent all day yesterday trying different approaches. I'll never be as good as all of you, but I do love programming. I did give both approaches here (and a few I found via google) a go. In the end, I went with the below. I know I've mangled your eloquent code, but I definitely appreciate the help.
Love this community.
Josh
global stopMe
on mouseUp
put true into stopMe
end mouseup
global counter, tCurrentProgress
on mouseUp
set backgroundcolor of graphic "tRect" to white
set backgroundcolor of graphic "tFill" to black
set the Width of graphic "tFill" to zero
set the left of graphic "tFill" to the left of graphic "tRect"
put 0 into counter
put 0 into tCurrentProgress
end mouseUp
global counter, tCurrentProgress, unit, stopMe
on mouseUp
put width of graphic "tRect" div 30 into unit
put false into stopMe
shrinkGrow 1
end mouseUp
on shrinkGrow tChange
if ((the altkey is down) or (stopMe is true)) then exit to top
put 1 into waitTime
if the width of graphic "tFill" < the width of graphic "tRect" then
set the width of graphic "tFill" to the width of graphic "tFill" + unit
set the left of graphic "tFill" to left of graphic "tRect"
--set the right of graphic "tFill" to right of graphic "tRect"
end if
if the width of graphic "tFill" >= the width of graphic "tRect" then
set the width of graphic "tFill" to 0
set the left of graphic "tFill" to left of graphic "tRect"
set the right of graphic "tFill" to right of graphic "tRect"
if the backgroundcolor of graphic "tFill" is yellow then set backgroundcolor of graphic "tFill" to black
if the backgroundcolor of graphic "tFill" is blue then set backgroundcolor of graphic "tFill" to yellow
if the backgroundcolor of graphic "tFill" is green then set backgroundcolor of graphic "tFill" to blue
if the backgroundcolor of graphic "tFill" is black then set backgroundcolor of graphic "tFill" to green
//do nothing
end if
send "shrinkGrow" && tChange to me in waitTime seconds
end shrinkGrow