Using the value of an object in a list

BlitzMax Forums/BlitzMax Beginners Area/Using the value of an object in a list

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

po,

I'll cover 3 OOP concepts and see if this is what you are trying to do:

OOP Concepts
Types
Instantiation
Constructors

You have Types Tminer and Tbase

When you instantiate (create an Object) from the miner Type, you want the x,y coordinates to be the same as the Base where he was created.

one way to do this is to create a special constructor function. With this function you can pass arguments to it (base coordinates) and also include setup info that all miners use (in my example-strength)

Type TMiner
   Field x:int
   Field y:int
   Field Strength:int

  ' constructor
  	Function Create:Tminer(basexpos , baseypos)
   		Local temp:Tminer = New Tminer
      	temp.x = basexpos
      	temp.y = baseypos
       temp.Strength = 100 ' default strength
      Return temp
  	End Function
  
End Type



call it by:
local newminer:Tminer = Tminer.create(mybase.x , mybase.y)


you can add it to your entitylist however you want (i.e listaddlast)