Type pointer

Blitz3D Forums/Blitz3D Programming/Type pointer

Moraldi(Posted 2006) [#1]
Is there any way to get a pointer of my type when I know one if its fields. Consider the following piece of pseudo code:

Type mytype

  field entity%
  .
  .
  .

end type

Global a_type_instance.mytype
.
.
.
for c=1 to CountCollisions(an_entity)
  entity_collided = CollisionEntity(an_entity, c)
  if entity_collided <> 0 then a_type_instance = ReturnAPointer(entity_collided)
next

Function ReturnAPointer.mytype(entity%)
 ???
end function



Note: I want to avoid to iterate the list of mytype

Thanks


Stevie G(Posted 2006) [#2]
No, but you can use the tried and tested object / handle method ...

Firstly, when creating the type instance, store the type handle in the entityname like so ..

n.mytype = new mytype
n\entity = createcube() 
nameentity( handle( n ) ) 


Then when you find your entity collided, simply get the object like so ..

Test.mytype = object.mytype( entityname( entity_collided) )
Test\Life = Tes\Life - 1 ;etc....


Should work just fine.

Stevie


Moraldi(Posted 2006) [#3]
I checked it and is working. This is what I was looking for!

Thank you so much Stevie!!!


Sir Gak(Posted 2006) [#4]
Yay, Stevie G! Good answer!


Moraldi(Posted 2006) [#5]
Well, sometimes when you get unstack you fill like a young boy he taste its first chocolate...