Author Topic: Timer disabled in BASIC  (Read 250 times)

0 Members and 1 Guest are viewing this topic.

Offline ivavilagu

  • CPC464
  • **
  • Posts: 10
  • Country: es
    • Awards
Timer disabled in BASIC
« on: 16:43, 08 December 21 »
Hi,
I have a countdown timer with 'EVERY' command. When the count reaches zero it disables with the function 'REMAIN'. It works fine.
But once disabled I can´t enable again the same counter. Remain function disables timer permanently?



like
0
No reactions

Offline abalore

  • CPC6128
  • ****
  • Posts: 211
  • Country: es
    • Awards
Re: Timer disabled in BASIC
« Reply #1 on: 17:04, 08 December 21 »
Why don't you better use AFTER?
like
0
No reactions

Offline abalore

  • CPC6128
  • ****
  • Posts: 211
  • Country: es
    • Awards
Re: Timer disabled in BASIC
« Reply #2 on: 17:08, 08 December 21 »
About your specific question, you must be sure you leave the timer subroutine with RETURN in order to be able to use the timer again. If it still fails try calling EI to enable interrupts.
like
0
No reactions

Offline ivavilagu

  • CPC464
  • **
  • Posts: 10
  • Country: es
    • Awards
Re: Timer disabled in BASIC
« Reply #3 on: 19:02, 08 December 21 »
I need to use EVERY for update the screen clock every second.
I don´t understand the RETURN command in this case. Where returned  when time is over?



Code: [Select]
IF second<>0THEN RETURN ELSE c=REMAIN(0):c$="GAME OVER":RETURN

I need to make a GOTO when game is over in order to start again.




Cohone, que somos los dos españoles, ¿se puede postear en castellano?



« Last Edit: 19:48, 08 December 21 by ivavilagu »
like
0
No reactions

Online andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.029
    • Awards
Re: Timer disabled in BASIC
« Reply #4 on: 01:30, 09 December 21 »
You need to RETURN from an EVERY subroutine or you will eventually run out of stack space. And it will return to whatever command was executing before the event triggered.


The trick to doing this sort of thing is to have the main block of code executing in a WHILE loop, checking a status variable to see if time has run out and then have your timer setting this variable.
like
0
No reactions

Offline ivavilagu

  • CPC464
  • **
  • Posts: 10
  • Country: es
    • Awards
Re: Timer disabled in BASIC
« Reply #5 on: 09:10, 09 December 21 »
Thanks, changed main loop and works!
like
0
No reactions