Int Pointers on type fields

BlitzMax Forums/BlitzMax Programming/Int Pointers on type fields

Tibit(Posted 2006) [#1]
Can I do:

Image.X = Varptr Ship.X .. Somehow?

So that the instance of Ship shares the same X in memory as image do, in this way I can have an image object that automatically updates to the ship once created.

I get an error when I do the above (X not found).

It seems like a simple thing to do. Anyone knows how to do it right?


Dreamora(Posted 2006) [#2]
You might try if defining x on the ship as int ptr instead of int helps.
But as the varptr were drastically reduced / removed some versions ago, I won't put too much hope in it. It was an unconsistency (ptr + managed = bad thing) that was removed .. you better put a reference to the image in your ship and simply get the x,y from the image each time the ship is drawn. (elegant way of doing it unless you have a true update method)


ImaginaryHuman(Posted 2006) [#3]
What about using a Global in the type?


Dreamora(Posted 2006) [#4]
Still it would need to be updated (update the ship when the image position changes or vice versa).

Global only makes the value unique to all instances (which normally wouldn't be very suited for positions)


Tibit(Posted 2006) [#5]
Hm..

A little note:
The reson I got "X not found" was that I was messing in the parent type, which did not have X or Y. The problem still remain:

Some test code which does not work:
Strict
Type TShip
	Field X,Y
EndType

Type TImage
	Field X,Y:Int Ptr
EndType

Local Ship:TShip = New TShip
Local Image:TImage = New TImage

Ship.X = 10
Ship.Y = 11
Image.X = 20
'Image.Y = 21 '<-- No longer an int 

Print "ShipX: "+Ship.X
Print "ShipY: "+Ship.Y
Print "ImageX: "+Image.X
Print "ImageY: "+Image.X

Int Ptr(Ship.X) = Varptr (Image.Y)
Ship.X = 88

Print "ShipX: "+Ship.X
Print "ShipY: "+Ship.Y
Print "ImageX: "+Image.X
Print "ImageY: "+Image.X



Dreamora(Posted 2006) [#6]
Image.X is not a valid assignement. It would be a pointer and thus can't be used like an int.

Image.X = Int Ptr(Ship.X)
Image.Y = Int Ptr(Ship.Y)

would b the correct assignement if ptr work at all.