Copying types

BlitzPlus Forums/BlitzPlus Beginners Area/Copying types

Yeshu777(Posted 2005) [#1]
Hi,

I'm probably doing something dull, but can anyone shed any light on how to copy a list of types into a backup list of types.

Type player
Field x_pos
Field y_pos
End Type

Type backup_player
Field x_pos
Field y_pos
End Type

Ideally I need to copy each instance of 'player' into a new list of types 'backup_player'

eg.

For my.player To Each player
copy.backup_player = New backup_player
copy.backup_player = my.player
Next

Or something similar, thanks to anyone who can shed any light on this as


Nicstt(Posted 2005) [#2]
copy them to a bank (poke), then copy from bank (peek).

As long as there are no strings involved its straight forward.


Grey Alien(Posted 2005) [#3]
Otherwise write your own copy function which copies all the fields across "manually". I do this to init a type from a template type.


Yeshu777(Posted 2005) [#4]
Being exceedingly cheeky...

Is it possible to furnish me with some sample code as I did
try this before to no avail - probably doing something stupid.

Thanks to all who replied.


Grey Alien(Posted 2005) [#5]
I can't give you the bank code but I have a type called Man and many functions that deal with the Man Type inc. this one:

Function ManInit(m.Man, t.Man) ;m = man to be Initialised, t = template to use
	m\ManType = t\ManType
	m\Active = 1
	m\x = t\x
	m\y = t\y
	m\XAcc = t\XAcc
	m\YAcc = t\YAcc
	m\CentreX# = t\CentreX
	m\CentreY# = t\CentreY
	m\XSpeed = t\XSpeed
	m\YSpeed = t\YSpeed
	m\Width = t\Width
	m\Height = t\Height
	m\Weight = t\Weight
	m\Health = t\Health
	m\HealthMax = t\HealthMax
	m\Shield = t\Shield
	m\ShieldMax = t\ShieldMax
	m\Power = t\Power	
	m\Direction = t\Direction
	m\Pattern = t\Pattern
	m\PatternCounter = t\PatternCounter
	m\PatternReset = t\PatternReset	
	m\ShootCounter = 0
	m\ShootMax = t\ShootMax
	m\CurrentImage% = t\TemplateImages
	m\CurrentFrame% = t\CurrentFrame
	m\Template = 0	
	
End Function



Yeshu777(Posted 2005) [#6]
Thanks for that, will give it a whirl.


Nicstt(Posted 2005) [#7]
i might have misunderstood your question, if i didnt, here is the code:). Most of it not required, just put in a few checking options.




Yeshu777(Posted 2005) [#8]
Thanks for all your help, I'll give both ideas a try over the weekend.