Reference to Object?

BlitzMax Forums/BlitzMax Programming/Reference to Object?

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.

Just create another object of type TEnemy, call it say 'TargetEnemy', and put it in your Missile object.

When you want to select a target for the missile, simply set Missile.TargetEnemy = GetRandomEnemyFromListFunction()

Oh, and don't forget to cast your object back to TEnemy when you grab it from the list, because a list returns everything as type object.

Anyhow, any variable of a user defined type is simply a reference to the actual object. Blitz doesn't copy by value on assignment, instead it changes the lvalues internal pointer.
e.g.
Enemy1:TEnemy = new TEnemy
Enemy2:TEnemy
Enemy1.name = "Enemy1"
Enemy2 = Enemy1 'enemy2 is now pointing to the same object as enemy 1
Enemy2.name = "Fred"
print Enemy1.name 'prints fred