Objects referring to objects

BlitzMax Forums/BlitzMax Programming/Objects referring to objects

gburgess(Posted 2006) [#1]
Excuse me if this is a dumb question. I've been learning Java in order to grow my OO chops, and I'm getting a good handle on it. I'm coming back to BMax for a bit now, since I was able to pick up the OO stuff far more easily in Java, and now wish to tinker with ideas again with BMax.

I've come up against something that's confusing me.

I have a member of my player object, 'host', which is supposed to refer to a 'host' object.

ie.

newplayer=player.create()
newplayer.host=host.create()

newplayer.host should now contain the pointer to a host object.

Is there a way I can access the members of host directly through this? ie newplayer.host.name$ (to access the name$ member of the host object who's handle is stored in newplayer.host)

Does this make any sense?


tonyg(Posted 2006) [#2]
Yes, exactly how you suggest so I'm not sure what problem you got while tinkering.
Type thost
	 Field name:String
End Type
Type tplayer
	 Field host:THost
End Type
my:tplayer = New tplayer
my.host = New thost
my.host.name = "blahblahblah"
Print my.host.name



Grey Alien(Posted 2006) [#3]
yeah it should work. Plus when I need to I make an alias e.g.

Local h:THost = newplayer.host
h.name = "blah"

This is more useful when maybe iterating through a list of objects and you want to refer to many fields of a sub-object.


gburgess(Posted 2006) [#4]
Yes, exactly how you suggest so I'm not sure what problem you got while tinkering.

The problem, Tony, is that I am a dumbass, you see.

Thank you both, I felt sure it ought to be possible, and your replies told me that I was just making an error. Turns out I hadn't set the host field in the player type to be of type host, it was an int.