Help with TYPES. Pulling hair here.

Blitz3D Forums/Blitz3D Programming/Help with TYPES. Pulling hair here.

Vertigo(Posted 2007) [#1]
Could someone please explain why this fails?!


Type Type1

End Type

Type Type2

End Type

typetype = 2

Select typetype

	Case 1

		This.Type1 = New Type1

	Case 2

		This.Type2 = New Type2

End Select



I NEVER selected the first case... so why did it assign This to that type? I chose case 2 so should that not omit the first case? Just try to run this code and you'll get a variable type mismatch. Does blitz throw pointers to types even if you dont call them?!!?!?

Any help or ideas around this would be great.. sorry im just at a loss here and going insane.

Thanks,
Scott


Techlord(Posted 2007) [#2]
Not exactly sure of what you trying to do, but, this will fail because the first case define This as a Type1, then you attempt redifine This in the second case as a Type2.


Jasu(Posted 2007) [#3]
A variable can be only of one type. It means that 'This' cannot be of Type1 or Type2. It has to be either one through the whole function/main without any conditionals. Blitz simply doesn't support this.

In my opinion this takes out the idea of using Object() and Handle() commands and multipurpose functions.


Vertigo(Posted 2007) [#4]
Thats just great. So you cant even fake function overloading with blitz then. I just find it weird that it allocates memory for that pointer even though it was not assigned. Basically im designing a combat function that allows multiple type objects to perform the same equations. Now instead of about 50 lines of code it will have to be damned near 300. *grumbles*. Thanks guys.


Curtastic(Posted 2007) [#5]
You can still fake it:

Type bomb
	Field s.sharedfields
	Field radius
End Type

Type player
	Field s.sharedfields
	Field name$
End Type

Type sharedfields
	Field x#,y#,speedx#,speedy#
End Type


b.bomb=New bomb
b\radius=22
b\s=New sharedfields

p.player=New player
p\name="joe"
p\s=New sharedfields

typetype = 2

Select typetype
	
	Case 1
		
		this.sharedfields = b\s
		
	Case 2
		
		this.sharedfields = p\s
		
End Select


this\x=this\x+this\speedx
this\y=this\y+this\speedy



Curtastic(Posted 2007) [#6]
Or you can fake it this way:
They work well.

Type bombfields
	Field radius
End Type

Type playerfields
	Field name$
End Type

Type thing
	Field x#,y#,speedx#,speedy#
	
	;only one of these is not null
	Field p.playerfields
	Field b.bombfields
End Type


tp.thing=New thing
tp\p=New playerfields
tp\p\name="joe"


tb.thing=New thing
tb\b=New bombfields
tb\b\radius=22

typetype = 2

Select typetype
	
	Case 1
		
		this.thing = tp
		
	Case 2
		
		this.thing = tb
		
End Select


this\x=this\x+this\speedx
this\y=this\y+this\speedy




Vertigo(Posted 2007) [#7]
Thanks Curtastic! I think you just gave me an idea. Also does anyone know if doing a for each loop on a set of objects speed is affected by the amount of data fields within the types.

For example.

Type1

field onlyone

end type

Type 2
Field 1
field 2
field 2 etc..
end type

Is searching through 200 of type 1 any faster than the same with type 2?

Thanks,
Scott


Danny(Posted 2007) [#8]
I'm guessing it doesn't. As far as I know Types are simply pointers to internal memory banks. I'm guessing that the only real difference is the 'amount of fields' you access/query during that loop...

But that's an uneducated guess...
Should be faily east to test & measure though..

D.


Matty(Posted 2007) [#9]
Effectively no speed difference, not anything worth measuring anyway.