best way to copy a type to a bank?

Blitz3D Forums/Blitz3D Programming/best way to copy a type to a bank?

Guan(Posted 2005) [#1]
Hi, is there a speedy way to copy a tpye to a created bank?


Nicstt(Posted 2005) [#2]
try this wrote it a few days ago for someone.

most of the code is for checks etc.

I've just finishing restoring a backup, so hope its ok:)




Guan(Posted 2005) [#3]
Thanks, nicoust, but it's a typical way in blitz to copy a type to a bank. Is there a way just like c++ does:
memcpy(&bank,&type,sizeof(type))?


Nicstt(Posted 2005) [#4]
nope nothing so straightforward.

Although its not as bad as my code looks, is only a few lines:)


Storm8191(Posted 2005) [#5]
Guan: there isn't an easy way to copy type data to a bank. However, there are ways to store type references to banks or plain integers. The Object and Handle keywords are probably the least properly explained tools in the Blitz3D language. Basically you can use Handle() to return an integer for your type instance, i.e. hand% = handle(mybaddie.typeObj). You can then use the object keyword to regain access to your type instance, i.e. yourbaddie.typeObj = object.typeObj(hand%). Since each type instance has its own unique number returned from Handle(), you'll always get the same object back.

Now, there's nothing stopping you from storing each of these integers in a bank, and so then you'll have your type instances listed in your bank. But don't go deleting the actual type instance, as then you'll loose all the data anyway. Granted this may not be anythig you're looking for, but I thought it was worth a mention anyway.

If you want to store the actual contents of your type instance within a bank, you'll have to do it manually, variable by variable, and write a function to do the reverse operation, and build a type instance. I think one of the reasons Blitz doesn't do deep copies is that it's hard to say how deep you can go, when one type may reference countless others of major importance.