[Closed] Quick question: arrays?
Just a quick question, if I want create an array call “MyArray” and give it two “properties” pos and dir, example:
MyArray = #([0,0,0] , [0,0,-1]);
and it should work to “call” MyArray.pos (MyArray[1]) and MyArray.dir (MyArray[2]);
Thanks.
You’re mixing two things here…
You’ve told maxscript that you want to make array with two items, but maxscript has no ID name-tags to know what those array values actually equate to.
You can get one by query an index of the array, myArray[1] or myArray[2] which return the point3, position, vector or whatever you want to call it.
When you first start using maxscript it’s pretty easy to just dump a load of values in an array and access them via indexing but I would personally learn to use structs as this makes coding so much easier to read and much more powerful. It depends on if you know the amount of items and what they are all going to be called.
Imagine this…
BMI = myArray[1] * myArray[2] / myArray[3]
or this
BMI = myVal.weight * myVal.height / myVal.age
Pretty clear which is simpler…
To make structs in maxscript you’ve got to define it first, this is some-what similar to object-orientated programming, so it’s not super simple for beginners…
myStruct =
(
pos = [0,0,0]
dir = [1,0,0]
)
Now you have to create an instance of this struct…
myVal = myStruct()
you can now set and access values by calling the properties…
myVal.pos
or
myVal.dir
Hope this helps.
Thanks, exactly what I were looking for
P.S: Had to add “struct” infront and remove the = and also add an comma “after / between the values” to get it to work.
struct myStruct
(
pos = [0,0,0],
dir = [0,0,-1]
)
myVal = myStruct()
print myVal.pos
print myVal.dir