timer as a base for an app

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

Post Reply
Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm

timer as a base for an app

Post by Samuele » Wed Jan 12, 2022 2:44 pm

hi, i wrote a script of a timer using the if statement like this

Code: Select all

on ActivateTimer
   HideStart
   if field "timer"  > 0
   then
   subtract 1 from field "timer"
   send ActivateTimer to me in 1 sec
   put the result into _pendingMessage 
      ---half game changes--- 
      else if field "timer" = 10 then
      show button "doublePoints"
      
      ---last minute changes---
   else if field "timer" = 5 then
      show button "bonus1000"
   else
      #StopMoveMe
      aeStopMoving "all"
      #hide button "Stop" with visual effect zoom out very fast  
      show button "Restart" with visual effect dissolve very fast
      show widget "Info" 
      show widget "Home" 
      show button "Settings" 
      GameOver
      DisableObjects
      HighScore
      HideBounuses
   end if
end ActivateTimer
but then like this the 'half game changes' and 'last minute changes' don't work (obviously, because if the field "timer" is 10 or 5 it's always greater than 0 so it will run only the first if and never the else if).
so i tried to change it from if to while like this:

Code: Select all

on ActivateTimer
   HideStart
   #if field "timer"  > 0
   #then
   repeat while field "timer"  > 0
   subtract 1 from field "timer"
   send ActivateTimer to me in 1 sec
   put the result into _pendingMessage 
   end repeat
      ---half game changes. pls correct the half number if necessary--- 
      if field "timer" = 10 then
      show button "doublePoints"
      
      ---last minute changes---
   else if field "timer" = 5 then
      show button "bonus1000"
   else
      #StopMoveMe
      aeStopMoving "all"
      #hide button "Stop" with visual effect zoom out very fast  
      show button "Restart" with visual effect dissolve very fast
      show widget "Info" 
      show widget "Home" 
      show button "Settings" 
      GameOver
      DisableObjects
      HighScore
      HideBounuses
   end if
end ActivateTimer
but the system freezes and it doesn't work, does anyone has an idea on how to make it work? (not necessarily with while or if like i did).
Thanks!
Samuele.

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

Re: timer as a base for an app

Post by dunbarx » Wed Jan 12, 2022 2:56 pm

You have set up your handler so that it never gets past the line:

Code: Select all

send ActivateTimer to me in 1 sec
On a new card, with a button and a field named "timer", I commented out all the things that I cannot use, like the other controls and the other handlers of which I know nothing. Also cleaned up the formatting a bit.

Code: Select all

on mouseup
   put 15 into fld "timer"
   ActivateTimer
end mouseup

on ActivateTimer
   if field "timer"  > 0 then
      subtract 1 from field "timer"
      send ActivateTimer to me in 1 sec
      put the result into _pendingMessage 
   end if
   
    if field "timer" = 10 then beep 2
   else if field "timer" = 5 then beep 3
end ActivateTimer
Craig

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm

Re: timer as a base for an app

Post by Samuele » Wed Jan 12, 2022 6:29 pm

yes! thanks!!!
Samuele.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: timer as a base for an app

Post by Klaus » Wed Jan 12, 2022 7:47 pm

Guys, do yourself a favour and put QUOTES around the message to send!

Code: Select all

send "ActivateTimer" to me in 1 sec
The engine is less forgiving with every new version when it comes to "sloppy" syntax. :D
I know since I had to learn this the hard way in the last 20 years!

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

Re: timer as a base for an app

Post by dunbarx » Wed Jan 12, 2022 8:03 pm

Klaus.

Right. I always do, but not with the slice and dice job I did with the OP's post.

@ Samuele. ALWAYS do that!!

Craig

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm

Re: timer as a base for an app

Post by Samuele » Wed Jan 12, 2022 8:08 pm

sorry :?
well thanks for the advice
Samuele.

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: timer as a base for an app

Post by Klaus » Wed Jan 12, 2022 8:38 pm

Really no need to apologize!

Post Reply