Dunno if this is a bug or not, but I noticed clones share the same vectors defined in Model.Definitions. Maybe it was because ZGE copy address of current vector to the clone instead of creating a new one?
You are right, this is because vectors are copied by address. I suggest you do "v=vector2(0,0);" in Model.OnSpawn to make it a new vector for every clone.
VilleK wrote:You are right, this is because vectors are copied by address.
But do you considered this to a bug? Having a pointer that points to the same memory space for each clone ( by default ) isn't exactly the desired behavior in my opinion. And when you do want to use the same vector from multiple clones you might as well just use a global vector ( and not waste memory on a pointer per clone ).
Ville, is there any special reason why vector variables are treated as pointers? BTW built-in vectors (such as ZApplication.MousePosition) are copied by values; which is little bit inconsistent.
I've seen that question in your email too, I haven't had a chance to reply because I've been away to Belgium to meet up with the Image-Line guys.
I agree it is not consistent the way it is.
That arrays are references and typing v1=v2 simply copies the reference is just like in C and C#, which are languages I like and take inspiration from. However that App.CameraPosition=v makes a value copy is confusing, it is because of legacy issues, App.CameraPosition is not internally of the same type as a vec3 in script so it needs to make a value copy. Maybe some day I can clean that up.
And I also agree that some kind of copyArrayElements function would be useful to have built in.
VilleK wrote:That arrays are references and typing v1=v2 simply copies the reference is just like in C and C#, which are languages I like and take inspiration from. However that App.CameraPosition=v makes a value copy is confusing, it is because of legacy issues, App.CameraPosition is not internally of the same type as a vec3 in script so it needs to make a value copy. Maybe some day I can clean that up.
In C you'd probably take this route .. in which case "v1 = v2" assigns the values ( instead of the address ).