Passing an instances name as a variable

BlitzMax Forums/BlitzMax Beginners Area/Passing an instances name as a variable

Lordfire(Posted 2005) [#1]
Hi, Not sure if this is still a newbie question. I have 2 types. One called Planet which orbits around a fixed point. Works ok. I have another type called satellite which I want to orbit around a planet. What I need help with is how do I pass the name of the planet type instance/object and then call its accessor methods from within the satellite type so I can have the satellite orbit around the centre of the planet.
Thanks


WendellM(Posted 2005) [#2]
Does something like this do the sort of thing that you need? Or were you wanting to pass a name$ ("Terra" in this example) rather than an instance name (Earth in this example)?
Strict


Type Planet

	Field Name:String

	Method GetName:String()
		Return Name
	End Method
	
End Type


Type Satellite

	Field Name:String


	Method SetOrbit( p:Planet )
		Print Name + " orbits " + p.GetName()
	End Method
	
End Type


Local Earth:Planet = New Planet
Earth.Name = "Terra"

Local Moon:Satellite = New Satellite
Moon.Name = "Luna"

Moon.SetOrbit( Earth )



Warpy(Posted 2005) [#3]
Nevermind, I'm a clod, just reread the previous post properly :P


Lordfire(Posted 2005) [#4]
About 30 minutes later I figured out something to try and I surprised myself and it actually worked.

Field orbitPlanet:Planet

Method SetSatelliteOrbit(p:Planet)
' record which planet to orbit
orbitPlanet = p
End Method

Method UpdateOrbitCentre()
orbitCentreX = orbitPlanet.getX()
orbitCentreY = orbitPlanet.getY()
End Method


Warpy(Posted 2005) [#5]
Oh, maybe I'm not a clod, that's what I had.