Timer not working

Moderators: LCMark, LCfraser

Post Reply
pink
Posts: 252
Joined: Wed Mar 12, 2014 6:18 pm

Timer not working

Post by pink » Wed Aug 22, 2018 8:40 pm

I'm trying to create a "button" that can be held down to increment a number

my plan was to use mouseDown to initiate a timer, but I keep getting a compile error

so really I have 2 questions:
1. how do I need to work my "schedule timer" command
2. is there a better way to try and hold down a button?

Code: Select all

public handler OnMouseDown()
   variable tNum as Number
   put mText parsed as number into tNum
   add 1 to tNum
   put numToString(tNum) into mText
   put true into mTester
   redraw all
   schedule timer in 1 second
end handler

public handler OnTimer()
   if mTester is true then
      put mText parsed as number into tNum
      add 1 to tNum
      put numToString(tNum) into mText
      put true into mTester
      redraw all
      if tNum < 100 then
         schedule timer in 1 second
      end if
   end if
end handler

public handler OnMouseUp()
   put false into mTester
end handler
the error:

Code: Select all

3:30 PM: Error: on line 142 (): 
3:30 PM: Error: /Users/pink/Dropbox/My LiveCode/Documents/LCB My Testground/PracticeWidget/pratice.lcb:142:36: error: Parsing error: syntax error
          schedule timer in 1 second
                          ^

3:30 PM: Error: failed to compile module
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

pink
Posts: 252
Joined: Wed Mar 12, 2014 6:18 pm

Re: Timer not working

Post by pink » Wed Aug 22, 2018 8:50 pm

ok, it was another error in the dictionary... should be "schedule timer in 1 seconds" not "schedule timer in 1 second"
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3302
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Timer not working

Post by bn » Wed Aug 22, 2018 9:12 pm

Greg,

Code: Select all

private variable mTester as Boolean
private variable mNumText as String

 public handler OnMouseDown()
    variable tNum as Number
    put "1" into mNumText
    put mNumText parsed as number into tNum
    add 1 to tNum
    put tNum formatted as string into mNumText
    put  not mTester into mTester
    redraw all
    schedule timer in 1 seconds
    log "mouseDown"
 end handler

 public handler OnTimer()
    variable tNum as Number
    if mTester is true then
       put mNumText parsed as number into tNum
       add 1 to tNum
       format tNum as string into mNumText
       put tNum formatted as string into mNumText
       put true into mTester
       redraw all
       if tNum < 10 then
          log tNum
          schedule timer in 1 seconds
       else
          log "TimeIsUp"
          put false into mTester
       end if
    end if
 end handler
adapt this to your situation but you put true into mTester in onMouseDown and false into onMouseUp

that effectively kills your timer right away unless you want to hold down the mouse for the testing period that is.

Kind regards
Bernd

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1561
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Timer not working

Post by monte » Wed Aug 22, 2018 11:47 pm

@Greg could you report this?
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “LiveCode Builder”