OOP - Nesting Objects

BlitzMax Forums/BlitzMax Programming/OOP - Nesting Objects

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

Type World
     Global Camera:Camera
End Type

Type Camera
     Field Player:Entity
End Type

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


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

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


Thanks Mr. Cower

Erm, Noel, doesn't your Camera class have a potential problem with cyclic references?

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?

Erm, aren't you both being overly nit-picky about a general example?

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.

Didn't read yours, just assumed ;)

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