Are Objects pointers?

BlitzMax Forums/BlitzMax Beginners Area/Are Objects pointers?

AndrewT(Posted 2009) [#1]
Ok, so if I understand correctly, all objects are actually just pointers. Is this correct? If I have something like this:

Local MyObject:TGameObject = New TGameObject
Local MyObject2:TGameObject = MyObject

MyObject2.X = 100


then does MyObject.X also equal one hundred, because both objects are pointing to the same data? I would test this myself right now but I'm writing this from my iPod.

Thanks. :)


Brucey(Posted 2009) [#2]
does MyObject.X also equal one hundred

Yes. They will both point to the same object in memory.


AndrewT(Posted 2009) [#3]
Thank you.


Htbaa(Posted 2009) [#4]
If you want to achieve the same thing with regular variables (integers, floats etc.) then you can use Var.


GfK(Posted 2009) [#5]
On a slightly related note - had a minor "palm on forehead" moment earlier.

Basically I wanted to switch some values contained within two types. I figured:

local type1:myType, type2:myType '(just for example)

Local temp:myType = type2
type2.imageframe = type1.imageframe
type1.imageframe = temp.imageframe

type myType
  field x:int
  field y:int
  field imageframe:int
end type
Of course, rather than swapping the values, the above resulted in two types with the same imageframe, since temp was simply an instance of type2.

Might be a dumb question but is there a way of creating a copy of an object, rather than an instance of an existing one? I'm sure there's a way but my brain is fried from coding magic spells all day (don't ask).


_Skully(Posted 2009) [#6]
I don't think there is...

Even if there was it would basically be complicated... I mean the type instance could be copied but what would that get you.. what if there is a TImage.. should it copy the image or just copy the reference as an example... or worse.. if there is a type reference within the type does it copy the referenced type as well or retain a reference..

Ultimately you will likely have to make your own copy function anyway...


Volker(Posted 2009) [#7]
Copy objects with reflection