Fast way to copy a class?

BlitzMax Forums/BlitzMax Programming/Fast way to copy a class?

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.

You'll have to write a copy routine. It would probably be best to write the routine as a Method in the type itself.
Type TLevel
   Field x:int
   Field data:int
   Field speed:Int

   Method CopyLevel(Level:TLevel)
      X = Level.X
      data = Level.data
      speed = Level.speed
   End Method
End Type

Local Level1:TLevel = new TLevel
....   Create all of level1's data
Local Level2:TLevel = new TLevel
Level2.CopyLevel(Level1) 'Copy level 1 data into Level 2


Supposedly, stuff like this has been made a little simpler with reflection, but I haven't messed with reflection any to give you any advice on it. Supposedly, you would "tag" the fields with a keyword, then in your copy routine, you would look for all the fields with that tag and copy it over. So later when you add more fields, you would not need to modify the copy routine.