field pointing to an object

BlitzMax Forums/BlitzMax Programming/field pointing to an object

CS_TBL(Posted 2006) [#1]
Type Poo
End Type

Type Pee
  Field mypoo:Poo
End Type

local a:Poo=New Poo
local b:Pee=New Pee
local c:Pee=New Pee
b.mypoo=a
c.mypoo=a


I guess this makes sense eh? b and c have a field which is kinda like an external field. Whenever I change a, b and c are automatically updated, since their Poo fields point to a. ('updated' is not the right word perhaps..)
The question is if this can only be with done objects? I'd like the same thing for normal variables (as option).. bytes, ints, float etc. How to do that?


H&K(Posted 2006) [#2]
Never use normal variables. Make a new type NInt with a field Int etc

Then you can


CS_TBL(Posted 2006) [#3]
I figured that already, which is what I do already, but I was hoping it was possible without this 'hack' ..


Grey Alien(Posted 2006) [#4]
no it's not possible. Unless maybe you want to get into pointers but that's worse (less easy to understant) tan making a TInt type.


H&K(Posted 2006) [#5]
@cs
I dont think there is.
I know I wanted to do this sort of thing and had a "flame" thread somewhere about it. And was told I was wrong so I should give up. I admit that I wanted this
Type NInt extends Int
Which is different to what you are asking, But as the answer I was given was,
"They (Types and internal objects), are not the same thing at all, they behave differently internaly and etc ..."
It probably is the same for this. (But Hah, I know nothing)


Grey Alien(Posted 2006) [#6]
yeah I wanted to do the same for arrays.


taxlerendiosk(Posted 2006) [#7]
Well, this *does* work:
Type TypeA
	Field value:Int
End Type

Type TypeB
	Field value:Int Ptr
End Type

a:TypeA = New TypeA
b:TypeB = New TypeB

b.value = Varptr(a.value)

a.value = 5
Print b.value[0]



H&K(Posted 2006) [#8]
We know. We've said it would
(All you've done is extend the original example)


AlexO(Posted 2006) [#9]
if you wanted a variable 'a:int' and 'b:int' to both update when 'c:int' was changed then you would make 'a' and 'b' int pointers. Which applies to any primitive type. That's what you seem to be trying to get at..or I may be wrong.


Who was John Galt?(Posted 2006) [#10]
@Grey

An array is an object so you should be able to have a (modifiable) array reference without a type wrapper.


Grey Alien(Posted 2006) [#11]
I wanted to extend an array type to add on some extra methods, but you can't do that.


Who was John Galt?(Posted 2006) [#12]
Ahh... stick... wrong end of... etc


Grey Alien(Posted 2006) [#13]
no worries, I didn't explain why I needed it :-)