Handles and objects

BlitzMax Forums/BlitzMax Beginners Area/Handles and objects

I've got some simple Blitz3d code that I want to import into BMAX. I have imported the BB project into Bmax but it don't work. The error I get is "Compile Error:Identifier 'HandleFromObject' not found"

I suspect the imported code is incorrect and that I should be using handles and objects in some other way... But how??

Here is the B3D code
Type timer
	Field Duration
	Field Value
	Field LastMs
End Type



; **************************************************

Function CreateTimers(Duration)

	t.timer = New timer
	t\Duration = Duration
	t\Value = Duration
	t\LastMs = MilliSecs()
	
	Return Handle(t)

End Function

; **************************************************

Function DeleteTimer(timer)

	Local t.timer = Object.timer(timer)
	Delete t
	
End Function

; **************************************************

Function UpdateTimers()


	Now = MilliSecs()
	For t.timer = Each timer
		t\Value = t\Value - (Now - t\LastMs)
		t\LastMs = Now
	Next
	
End Function


; **************************************************

Function ResetTimer(timer,value = 0)
	
	Local t.timer = Object.timer(timer)
	If value = 0 Then
		t\Value = t\Duration
	Else
		t\Value = Value
	EndIf

End Function

; **************************************************

Function GetTimerValue(timer)

	 Local t.timer = Object.timer(timer)
	 Return t\value
End Function

Here is the bMAX imported code
Import "bbtype.bmx"
Import "bbvkey.bmx"

Global timer_list:TList=New TList
Type bbtimer Extends TBBType

	Method New()
		Add(timer_list)
	End Method

	Method After:bbtimer()
		Local t:TLink
		t=link.NextLink()
		If t Return bbtimer(t.Value())
	End Method

	Method Before:bbtimer()
		Local t:TLink
		t=link.PrevLink()
		If t Return bbtimer(t.Value())
	End Method

	Field Duration
	Field Value
	Field LastMs
End Type



' **************************************************

Function CreateTimers(Duration)

	t:bbtimer = New bbtimer
	t.Duration = Duration
	t.Value = Duration
	t.LastMs = MilliSecs()
	
	Return HandleFromObject(t)

End Function

' **************************************************

Function DeleteTimer(timer)

	Local t:bbtimer = bbtimer(HandleToObject(timer))
	t.Remove()
	
End Function

' **************************************************

Function UpdateTimers()


	Now = MilliSecs()
	For t:bbtimer = EachIn timer_list
		t.Value = t.Value - (Now - t.LastMs)
		t.LastMs = Now
	Next
	
End Function


' **************************************************

Function ResetTimer(timer,value = 0)
	
	Local t:bbtimer = bbtimer(HandleToObject(timer))
	If value = 0 Then
		t.Value = t.Duration
	Else
		t.Value = Value
	EndIf

End Function

' **************************************************

Function GetTimerValue(timer)

	 Local t:bbtimer = bbtimer(HandleToObject(timer))
	 Return t.value
End Function


I'd be tempted to make the timer parameter in those functions of type bbTimer then you simply reference it directly instead of creating a temp timer.

Perturbatio, could you demonstrate what you mean.

Thanks.

ok, something like this:
Import "bbtype.bmx"
Import "bbvkey.bmx"

Global timer_list:TList=New TList

Type bbtimer Extends TBBType

	Method New()
		Add(timer_list)
	End Method

	Method After:bbtimer()
		Local t:TLink
		t=link.NextLink()
		If t Return bbtimer(t.Value())
	End Method

	Method Before:bbtimer()
		Local t:TLink
		t=link.PrevLink()
		If t Return bbtimer(t.Value())
	End Method

	Field _Duration
	Field _Value
	Field _LastMs
	
	Function Create:bbtimer(Duration:Int)
		Local tempTimer:bbTimer = New bbTimer
		   tempTimer._Duration = Duration
		   tempTimer._Value = Value
		   tempTimer._LastMs = MilliSecs()
		Return tempTimer
	End Function

End Type



' **************************************************

Function UpdateTimers()


	Now = MilliSecs()
	For t:bbtimer = EachIn timer_list
		t._Value = t._Value - (Now - t._LastMs)
		t._LastMs = Now
	Next
	
End Function


' **************************************************

Function ResetTimer(timer:bbTimer,value = 0)
	
	If value = 0 Then
		timer._Value = timer._Duration
	Else
		timer._Value = Value
	EndIf

End Function

' **************************************************

Function GetTimerValue(timer:bbTimer)
	 Return timer._value
End Function 

probably some errors in there, but it should demonstrate

I see,

Thanks, I think I got my head around it now.