Page 1 of 1

timer as a base for an app

Posted: Wed Jan 12, 2022 2:44 pm
by Samuele
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!

Re: timer as a base for an app

Posted: Wed Jan 12, 2022 2:56 pm
by dunbarx
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

Re: timer as a base for an app

Posted: Wed Jan 12, 2022 6:29 pm
by Samuele
yes! thanks!!!

Re: timer as a base for an app

Posted: Wed Jan 12, 2022 7:47 pm
by Klaus
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!

Re: timer as a base for an app

Posted: Wed Jan 12, 2022 8:03 pm
by dunbarx
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

Re: timer as a base for an app

Posted: Wed Jan 12, 2022 8:08 pm
by Samuele
sorry :?
well thanks for the advice

Re: timer as a base for an app

Posted: Wed Jan 12, 2022 8:38 pm
by Klaus
Really no need to apologize!