[Closed] Changing values of referenced variable array
There is something I want a function to do, but I’m not sure how to proceed. I’m an amateur programmer/maxscripter, so you have to excuse me if this is impossible, stupid or both!
I have a bunch of variables I’d like to change in one go. They are holding coordinates, but need to be accessed as individual named variables, like this:
headPos = [x,y,z]
chestPos = [x,y,z]
… and so on
I was going to write a function to do this, and I was assuming I could pass them into the function as a referenced array, like this:
varArray = #(headPos, chestPos, …)
function changeVars &varArray =
(
for v in varArray do v = [newX, newY, newZ]
)
but if I do that, the variables gets cleared out, and the array looks like this:
varArray = #([newX, newY, newZ], [newX, newY, newZ], …)
Am I doing something that isn’t possible? And if I am, is there a better way of doing this?
Thanks!
You could do it like this:
fn changeArray &arr =
(
*arr[1] = "foo"
*arr[2] = "bar"
)
a = "der"
b = "dum"
c = #(&a, &b)
changeArray c
Though honestly, I can say I’ve never had to do something like this, so there is probably a simpler way.
I think you may need to directly set the array index values.
function changeVars &varArray =
(
for v in varArray do v[1] = newX; v[2] = newY; v[3] = newZ
)
Though I haven’t tried it.
-Eric