[Closed] Struct Copy Question
So if you have a struct say
Struct Test (A,B)
and you have a variable
Var1 = Test 1 2
Var2 = Var1
Whatever happens to Var1 happens to Var2. I’m with it so far.
But then if I do copy:
Var2 = copy Var1
Now if I change Var1.A Var2 stays unique.
But if I were to have a piece of data such as:
Var1 = test [1,2] [3,4]
Var2 = copy Var1
Var2.A = [3,4] – Var2 stays unique from Var1
Var1.A.X Var2 – now Var2 WOULD change? Why?
How do I get an independent new struct but with the same data? Particularly in reference to working with functions. I would like to take in a struct. Do stuff to its data and return a new struct for use.
Also I sometimes when working with structs get this error message:
-- Compile error: Undeclared variable: variable
-- In line: variable
I don’t know how to get out of it.
I can hit escape and it says interrupted but I’m unable to use the listener anymore.
How to do I close out whatever it’s expecting and get back to normal?
Something’s missing in your example code. If you mean something like:
“Var1.A.X = 5 – Var2 now has A.X as 5 as well”
Can’t say I can confirm that. I do see that with an array, of course:
var3 = test #(1,2) 3
Test a:#(1, 2) b:3
var4 = copy var3
Test a:#(1, 2) b:3
var3.a[1] = 4
4
var3
Test a:#(4, 2) b:3
var4
Test a:#(4, 2) b:3
have to deepCopy any array members explicitly.
That makes two of us. When I get that error, I can type “a = 5” in the Listener and MaxScript will just throw “undeclared variable: a” at me. Have to restart max for anything to be useful again.
Ohhhhhhhhhhhh ok. My brain just clicked. Now I get it.
The array that was in the struct is its own block of data. When you copy the struct it’s like
A= #(1,2,3)
B = A
So even though the struct’s pointer has been broken the array’s hasn’t.