Handles and objects

BlitzMax Forums/BlitzMax Beginners Area/Handles and objects

TartanTangerine (was Indiepath)(Posted 2004) [#1]
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



Perturbatio(Posted 2004) [#2]
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.


TartanTangerine (was Indiepath)(Posted 2004) [#3]
Perturbatio, could you demonstrate what you mean.

Thanks.


Perturbatio(Posted 2004) [#4]
ok, something like this:

probably some errors in there, but it should demonstrate


TartanTangerine (was Indiepath)(Posted 2004) [#5]
I see,

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