OOP - Nesting Objects

BlitzMax Forums/BlitzMax Programming/OOP - Nesting Objects

gellyware(Posted 2005) [#1]
Does anyone have an example of how to nest objects so that you would see something like the following syntax:

world.camera.player.y = something


N(Posted 2005) [#2]
Type World
     Global Camera:Camera
End Type

Type Camera
     Field Player:Entity
End Type

Type Entity
     Field X#, Y#, Z#
End Type



gellyware(Posted 2005) [#3]
Thanks Noel, how would you initialize it?

Would it just be:

game:World = new World

and then I would have access to game.camera.player.y?

or would it be:

Earth:World = new World
Earth.Camera = new Camera
Earth.Camera.Entity = new Entity
Earth.Camera.Entity.Y = 50


N(Posted 2005) [#4]
Well in the case you want planets...

Type Scene
  Field Camera:Camera = New Camera
  Field Worlds:TList = New TList
End Type

Type Camera
  Blah
  Field Owner:Entity ' Can be any object, a player entity included
  Field Children:TList = New TList ' Children entities
End Type

Type Entity
  Field X#, Y#, Z#, Etc
End Type

Type Player Extends Entity
  Blah
End Type



gellyware(Posted 2005) [#5]
Thanks Mr. Cower


FlameDuck(Posted 2005) [#6]
Erm, Noel, doesn't your Camera class have a potential problem with cyclic references?


Koriolis(Posted 2005) [#7]
Unless he puts a camera instance in the 'Children' list, no. Given that his Camera class doesn't extend Entity why would you want to put a camera in this list anyway?


N(Posted 2005) [#8]
Erm, aren't you both being overly nit-picky about a general example?


Koriolis(Posted 2005) [#9]
Me? I was replying to the nit picky one. You were supposed to read the above as "there's no problem here", I don't think that's being nit picky.
Actually even FlameDuck was not that nit picky, it's good to point these issues. He was just wrong here.


N(Posted 2005) [#10]
Didn't read yours, just assumed ;)

As for FlameDuck, he's just being a hoebag.