I can't seem to figure out how to write this. I want a function to be able to modify a property.
fn myFunc n attribute value =
(
n.attribute = value
)
myFunc $ height 50
It will tell me that my object n doesn't have a property called 'attribute'.
What's the syntax for this?
Replies
well I'll go on a limb here - to do what you are trying to do, look up the 'execute' command. In all honesty using it is usually shonky, but if it's for a quick and dirty script why the hell not try it.
There is another way to check for the presence of attributes/properties and then work on them - look up hasproperty and isproperty and how they work.
Have fun!
You will also need to pass "height" as a string - currently you're trying to pass it as a variable, therefore it will end up passing undefined at the moment (unless you defined height as a string value of "height" earlier in the code, which seems unlikely).
Try this:
Edit: Beaten to the punch by cw! But mine has a tested working code example
Edit2: Actually this is really dodgy since I'm using $<name> to set the property, which is bad since you might have multiple objects in the scene with the same name.
There's probably a better way to get the actual node in there, I'm just too lazy to look it up at the moment
Cheers all.
just confused as to why you have to use the execute command within the function
You have to pass the variables to the function as strings because you can't just access the node properties for any generic attribute (since height on its own is just a variable name, not a property of an object).
ah thanks for clearing that up MoP
Ok MoP, I see your code example and raise you another (just for fun, like..)
There are long and complex reasons why I didn't post one originally, revolving around sudoku and nintendo DS. I shan't bore you with all that though. Have fun!
I knew execute seemed pretty dodgy... I've been out of the loop on maxscript for a few years now though
Strangely, 'hasProperty' will return false if you're querying about a custom attribute. 'isProperty', however, will work just fine.
I ran into issues earlier when I also needed to test the state of a property as well, since I couldn't get at it with the usual object '.' notation. But I ran across a getProperty function after seeing your example using setProperty.
I love simple solutions.