Abstract Types and design
BlitzMax Forums/BlitzMax Programming/Abstract Types and design
| ||
An abstract type means you can't make an instance of it. It's supposed to be used when you inherit. But I'm doing this:Type FPSCounter Abstract Global Draws:Int Global DrawTime:Int Global FPS:Int Function Update() If MilliSecs()-drawtime>=1000 Then fps=draws draws=0 drawtime=MilliSecs() Else draws:+1 EndIf EndFunction Function Draw() SetColor 255,255,255 DrawText "FPS: "+fps,1,1 EndFunction EndType Everything works fine, except the debugger won't show the values of these globals when the program is stopped. I think it assumes you would never do what I am doing. Is doing this a bad idea? I'm just calling it abstract to show that you never make an instance of it. |
| ||
I hope not. I do this too. |
| ||
The debugger should show the values regardless of whether it's abstract or not. Global values have nothing to do with it since they are not restricted to an instance of the object. I'd say that's a bug in the debugger. |
| ||
Try putting your global variables outside the type. |
| ||
Global values have nothing to do with it since they are not restricted to an instance of the object I asked about this quite a long time ago, and everyone told me I was stupid for asking. But the problem is when are the Globals of a type to be initialised. Is it to be the first time an object is created (I think not, but might be), is it the first time the object is referenced, (I dont know, but would not happen for an abstract type), is it at the start of runtime, (Most people said yes to this) Now add to this problem the fact that you have made your type abstract, and it becomes more of a problem. @Curtastic You havent said what you are doing, you have just shown the type, what are you doing with it? If you arent doing anything, then its probable that the gloabal simply dont exist until you do something |
| ||
@Gabriel, Good I'm not the only one! @Jim, I agree. @Sean Doherty, I want everything to be inside types. @H&K, It's just a normal frames per second counter, and the globals are definately created. Here's some better code: Strict Type FPSCounter Abstract Global Draws:Int = Test() Global DrawTime:Int Global FPS:Int Function Update() If MilliSecs()-drawtime>=1000 Then fps=draws draws=0 drawtime=MilliSecs() Else draws:+1 EndIf EndFunction Function Draw() SetColor 255,255,255 DrawText "FPS: "+fps,1,1 EndFunction EndType Graphics 555,555 Print "Main loop" Repeat If KeyHit(key_escape) Then End fpscounter.update() fpscounter.draw() Flip Cls If MouseHit(1) Then DebugStop Forever Function Test() Print "Globals initialized" EndFunction |
| ||
Yep, my vote for a debugger problem |
| ||
I think it's a bug but don't understand what 'abstract' has to do with it. Take abstract out and you don't see the values either... or am I missing something? |
| ||
Nope, you're quite correct. It does not place the type into the debugger at all until you create an instance, regardless of whether or not its abstract. |