Thanks Irv,

tried and yes (of course) it works but it will be a while
yet before I can feel competent and confident enough to
write scripts like yours...I'm working on it! (Honest!)

Thanks
JohnT



Irv Kalb wrote:

> John,
>
> Globals!  Globals!  We don't need no stinking globals!
>
> But seriously, here is a case where an object oriented approach fits
> very nicely.  It also is a good case that demonstrates what an
> earlier poster today was saying about repeat loops.  In your code,
> you have a repeat loop constantly running updating a field on screen.
> So, while your code displays correctly, you have effectively locked
> out any user interaction because of your "tight" repeat loop.
>
> Another approach is to use a behavior attached to a field or text
> member.  The behavior would check the time every exit frame event,
> and update the display whenever it needs to.  This way, it would
> allow for any other interactivity your program wants to do.  And,
> because it is a behavior and does its own time tracking using its own
> property variables, there is no need to use "startTimer".  So, by
> using a behavior you can have as many count down timers running
> concurrently as you want.  Try dropping this behavior onto a field or
> text member and see if it does what you want:
>
> -- Countdown timer
>
> property spriteNum
> property pStartingMilliseconds  -- milliseconds where counting started
> property pStringCurrentlyDisplayed  -- copy of string currently displayed
> property pTotalMilliseconds  -- total milliseconds to count down
> property pfDone  -- FALSE until done, then TRUE
>
> on beginSprite me
>    -- set this to the number of seconds you want to count
>    -- or replace this with a getPropertyDescriptionList where user
> enters a number
>    startingSeconds = 10
>    pTotalMilliseconds = (startingSeconds + 1) * 1000
>    pStartingMilliseconds = the milliseconds
>    pfDone = FALSE
> end
>
> on exitFrame me
>    if pfDone then
>      return  -- nothing more to do
>    end if
>
>    -- A little math
>    millisecondsElapsed = the milliseconds - pStartingMilliseconds
>    countDownMilliseconds = pTotalMilliseconds- millisecondsElapsed
>    if countDownMilliseconds <= 0 then
>      countDownMilliseconds = 0  -- don't go negative on me!
>    end if
>    me.mDisplay(countDownMilliseconds)  -- show it
> end
>
> on mDisplay me, nMillisecondsToDisplay
>    secondsToShow = nMillisecondsToDisplay / 1000  -- integer divide,
> throws away fractional amount
>    stringToDisplay = string(secondsToShow)
>
>    -- This is an optimization, only update the string if it is different
>    -- from what we already have
>    if stringToDisplay <> pStringCurrentlyDisplayed then
>      sprite(spriteNum).member.text = stringToDisplay
>      pStringCurrentlyDisplayed = stringToDisplay
>
>      -- Check for done
>      if pStringCurrentlyDisplayed = "0" then
>        alert("Done")  -- do whatever you want here
>        pfDone = TRUE
>      end if
>    end if
>
> end
>
> If this doesn't make sense, add a few breakpoints and step through
> the handlers with the debugger until you see what's going on.
>
> Irv
>
> At 7:47 AM +1000 10/25/01, John Trentini wrote:
> >Hi guys,
> >
> >I have made a timer to countDown from 10 seconds
> >to zero and it works but I cannot understand why I
> >had to subtract an additional value of one from the following line:
> >
> >   gMyTime = 10 - (gMyTime -1) -1
> >
> >without this the counter will start from 11 rather than 10.
> >
> >I would have thought that :
> >   gMyTime = 10 - (gMyTime -1)
> >would do the job but...
> >
> >
> >Can anyone be kind enough to explain this to me?
> >
> >
> >Here is the full code:
> >
> >on prepareFrame
> >   set the text of field "Ten" = ""  --resets the text to empty
> >end
> >
> >
> >on exitFrame me
> >   global gMyTime
> >   startTimer
> >   go to the frame
> >   repeat while the timer <= 10*60  --10 seconds
> >     Ctime
> >     put gMyTime into field "Ten"
> >   end repeat
> >   halt
> >
> >end
> >
> >on Ctime
> >   global gMyTime
> >   gMyTime = the timer /60  -- set the timer to seconds
> >   gMyTime = 10-(gMyTime-1)-1  --detract one with each second
> >
> >end
> >
> >Thanks
> >
> >JohnT
> >
> >
> >
> >[To remove yourself from this list, or to change to digest mode, go to
> >http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
> >email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
> >Lingo-L is for learning and helping with programming Lingo.  Thanks!]
>
> --
>
> Lingo / Director / Shockwave development for all occasions.
>
>    (Home-made Lingo cooked up fresh every day just for you.)
>
> [To remove yourself from this list, or to change to digest mode, go to
> http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
> email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
> Lingo-L is for learning and helping with programming Lingo.  Thanks!]


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to