CPCWiki forum

General Category => Programming => Topic started by: ivavilagu on 15:43, 08 December 21

Title: Timer disabled in BASIC
Post by: ivavilagu on 15: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?



Title: Re: Timer disabled in BASIC
Post by: abalore on 16:04, 08 December 21
Why don't you better use AFTER?
Title: Re: Timer disabled in BASIC
Post by: abalore on 16: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.
Title: Re: Timer disabled in BASIC
Post by: ivavilagu on 18: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?



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?



Title: Re: Timer disabled in BASIC
Post by: andycadley on 00: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.
Title: Re: Timer disabled in BASIC
Post by: ivavilagu on 08:10, 09 December 21
Thanks, changed main loop and works!
Powered by SMFPacks Menu Editor Mod