Types. Help anyone?

BlitzMax Forums/BlitzMax Beginners Area/Types. Help anyone?

Takuan(Posted 2006) [#1]
Crap!


H&K(Posted 2006) [#2]
Have you got all the terms right in your question?

Do You mean you want the field to point to different Types?

I think (and Im by no means sure), that you "point" the field to a default "Object".

The thing is your example has muh, weow and wuff, which are all the same type (sounds), which (sort of), contradicts what you have said above it. So reword the example to show what you really mean


Perturbatio(Posted 2006) [#3]
The thing is your example has muh, weow and wuff, which are all the same type (sounds), which (sort of), contradicts what you have said above it. So reword the example to show what you really mean


Only in the world of pedantia can someone not understand what he means :)

but yes, use the Object type, the problem is you need to cast it if you want to refer to any fields or methods of the actual type.


H&K(Posted 2006) [#4]
I dont think I am being Pedantic here Perurb, I think there is a genuine posibility that he ment
a:Sound = Muh
currenttype:sound= a
And it was worth checking.
Do you have a link to a "Pointer to Type" tutorial


Dreamora(Posted 2006) [#5]
To declare a type to easily retrieve it, you can add a string field in which you write the current type.

There is nothing like in Java with reflection etc to find out a type at runtime (although it is internally present) without the need to cast it and see if the answer is null


Takuan(Posted 2006) [#6]
Dang, my example was crap, sry.

I wanted one identifier (variable) which should point to different objects which are instances of different user defined types (according the manual that terms should be right now;).

Anyway, that works but seems a little ugly:

Type A
Field x
End Type

Type B
Field y=10
Field z=20
End Type

Global obj1:A=New A
Global obj2:B=New B

Local currentobject:Byte Ptr=Byte Ptr(obj2)
Print currentobject[0]

I dont want to remember what index nr in currentobject stands for what field.


Maybe that aproach would be better?

Type A
Field x
End Type

Type B
Field y=10
Field z=20
End Type

Global obj1:A=New A
Global obj2:B=New B

global currentobject:object=obj2

"currentobject" now refers to obj2, but how to retreive any values/fields from it?


Perturbatio(Posted 2006) [#7]
but yes, use the Object type, the problem is you need to cast it if you want to refer to any fields or methods of the actual type.



Diablo(Posted 2006) [#8]
Edit: Argh beaten.. oh well at lest i post code WHAHAHA! lol

typecast is what you need...

Type A
Field x
End Type

Type B
Field y=10
Field z=20
End Type

Global obj1:A=New A
Global obj2:B=New B

global currentobject:object=obj2

print b(currentobject).y
print b(currentobject).z

' print a(currentobject).x ' Wont work



Perturbatio(Posted 2006) [#9]
typecast is what you need...


Except he can't because he wants to store an object without knowing what type it is.

Short of cycling through all the predicted types he will use and casting until he gets a hit, there's no way to determine the type.


Takuan(Posted 2006) [#10]
Thank you all, think i will take byte ptr (in hope it wont blow something up;)
That code example should be in the manual.