Timer help needed

BlitzMax Forums/BlitzMax Beginners Area/Timer help needed

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's the timekeeping part of my current project, you might find it useful...

Type _Timer Final

	Field Active:Byte
	Field LastTick:Int
	Field Frequency:Int
	Field Tick:Byte

	Method Update:Byte()
		If Active = True
			If LastTick + Frequency < MilliSecs()
				Tick = True
				LastTick = MilliSecs()
			EndIf
		EndIf
	End Method

	Method HasTicked:Byte()
		If Tick = True Then Tick = False; Return True
		Return False
	End Method

	Method Activate:Byte()
		Active = True
		LastTick = MilliSecs()
	End Method

	Method DeActivate:Byte()
		Active = False
	End Method

	Method SetFreq:Byte( NewFreq:Int )
		Frequency = NewFreq
	End Method

	Method GetTimeSinceLastTick:Int()
		Return MilliSecs() - LastTick
	End Method

End Type


Then use it like this
t:_Timer = New _Timer
t.SetFreq(1000)
t.Activate()

blah blah...

t.Update()
If t.HasTicked() = True, 'Display next text


exactly the same as LarsG's example, just more long winded and harder to follow ;)