Page 1 of 1

timer eventually speeds up

Posted: Sun Aug 30, 2015 3:22 pm
by ittarter
Hello!

My timer is buggy. I send updatetimer on preloadcard, and the first time the card is loaded it works like a charm. When I leave the card, gTimerOn is false, but updatetimer is still being sent. Then, when I reload the card, updatetimer is a sent a second time, which stacks onto the first.

Now, I was able to solve this problem by moving the last line of the following code INTO the conditional, and sending updatetimer again with a button that unpauses it (I need to be able to pause and unpause the timer, but the timer is only reset when the card is loaded). That way updatetimer "dies out" and can't stack when I put false into gTimerOn.

Code: Select all

on updatetimer
   global gTimerOn, gSeconds
   if gTimerOn is true then 
      add 1 to gSeconds
      put gSeconds into fld "Timer"
   end if
   send updatetimer to me in 1 second
end updatetimer
I was just wondering if there was a more elegant way of controlling/limiting messages being sent to a card, e.g. when you close the card, all pending messages are cancelled. I tried writing some code to that effect (e.g. cancel the last line of the pendingmessage) but got a lot of error messages so obviously I wasn't doing it correctly.

Re: timer eventually speeds up

Posted: Sun Aug 30, 2015 11:59 pm
by bn
Hi ittarter,

if you want to get rid of your pending messages when changing cards you could put this code into the card script

Code: Select all

on closeCard
   repeat for each line aMessage in the pendingMessages
      if aMessage contains "myMessage" then cancel item 1 of aMessage
   end repeat
end closeCard
especially if your messages pile up you would want to cancel all occurences of your pendingMessages, therefore repeat

You could also do a command like the one in the user contributions of the dictionary entry for "pendingMessages"

Code: Select all

ON cancelThisMsg tMsg
   put the pendingmessages into tPendingMsgs
   IF tMsg is in tPendingMsgs THEN
      repeat FOR each line x in tPendingMsgs
         if tMsg is in x THEN cancel item 1 of x
      end REPEAT
   END IF
END cancelThisMsg
you would call it

Code: Select all

put "myMessage" into tMsg
cancelThisMsg tMsg
you could put the code into the stack script and call it from "closeCard"

Don't forget to cancel your pendingMessages on Quit. But since there is a closeCard message sent when you quit it would be OK either way

Kind regards

Bernd

Re: timer eventually speeds up

Posted: Mon Aug 31, 2015 12:48 am
by ittarter
Thanks, Bernd! This is exactly what I was looking for.

So, how do I find out what my messages are named and their content, so I can use this code? Can I really leave the code as-is with variables like aMessage and strings like "MyMessage"?