I'm not supposed to be here, I have a project to do (and an angry friend if he catches me slacking). I promised I'd just lurk to stay abreast of things until I was finished my project and the stuff I'm helping my mate with yet here I am...
Oh well, couldn't resist...
1) Hodgey's code is perfect. There are no "errors". It's simply not being implemented correctly.
2) Your program gets stuck in a loop because of structuring.
1). Use Hodgey's code but
remove all CLS statements from your code and replace all PRINT statements with TEXT. Now use the following code at startup, after setting up your display:
BACKDROP ON: COLOR BACKDROP RGB(0,0,0)
rem Activates 3D mode. Screen is now being constantly refreshed. You can
rem lose SYNC ON and the SYNC statements too and stick this at the beginning instead:
SYNC RATE 60
Before you say "it's all gone black", see number 2
2). Make every call [sub/function] a dynamic one. DO..LOOP in most cases should be avoided in functions/subs. Example:
`Declare vars
GLOBAL maxhealth = 100
GLOBAL curhealth = 100
GLOBAL regentimer = 0
`Setup Display
SET DISPLAY MODE DESKTOP WIDTH(), DESKTOP HEIGHT(), 32
SYNC RATE 60
BACKDROP ON
COLOR BACKDROP RGB(0,0,0)
`Main Loop
DO
`etc, etc
TEXT 1, 20, "Your health is: " + STR$(curhealth) + "/" + STR$(maxhealth)
TEXT 1, 60, "KEYS:"
TEXT 1, 80, "1 = Deplete health to 50%"
TEXT 1, 100, "Esc = exit"
IF curhealth < maxhealth: Regen(): ENDIF
IF curhealth =< 0: EXIT: ENDIF
IF VAL(INKEY$()) = 1: curhealth = 50: ENDIF
LOOP
END
Function Regen()
rem This is what Hodgey was using; a timer for Regeneration.
IF TIMER() - Regentimer > 100
INC curhealth
regentimer = TIMER()
ENDIF
EndFunction
Dynamic coding makes life easier once the habit is formed. Using 3D screen mode even for text-based things actually BETTER because you'll end up using less statements, especially where PRINT and CLS are concerned so your code becomes neater and more compact and, ultimately, easier for you and the machine to handle.
Hopefully this clarifies it all. Good luck.